<p>We just changed this behavior in <a href="http://buildwithcraft.com/updates#build2616" rel="nofollow">Craft 2.3.2616</a>:</p>

<blockquote>
  <p>Live Preview and Share links will now show the unpublished entry/category changes wherever the entry/category are being referenced in the templates (even areas where the entry/category was fetched from the database).</p>
</blockquote>

<p>So now Live Preview (and Share links) should work as expected for you.</p>

CC BY-SA 3.0
2014-12-03T23:42:51.283Z
I like this kind of answers!
carlcs
CC BY-SA 3.0
2014-12-04T03:02:44.297Z
this is amazing! thanks for listening Brandon :). Sorry @carlcs, but I'll have to change the correct answer to this one, since I went back and updated my template to reflect this change.
Brian Whitton
CC BY-SA 3.0
2014-12-04T08:23:11.837Z
No way, @noSlouch! Now that I was so creative and found a solution for this, I insist that YOU stick to it.
carlcs
CC BY-SA 3.0
2014-12-03T22:41:07.347Z
2014-12-03T22:41:07.347Z
Brandon Kelly
<p><strong>Update:</strong></p>

<p>Thanks to P&amp;T this workaround is not necessary any more with <a href="http://buildwithcraft.com/updates#build2616" rel="nofollow">Craft 2.3.2616</a>!</p>

<p><br></p>

<p><em>This was my temporary solution / bugfix:</em></p>

<hr>

<p>I think you're right, Live Preview seems to only update if changes to the automatically provided <code>entry</code> EntryModel are detected.</p>

<p>So this causes problems with Live Preview:</p>

<pre><code>{# Get `entry` manually #}
{% set home = craft.entries.section('home').first() %}
{{ home.welcome }}
</code></pre>

<p>while this works fine:</p>

<pre><code>{{ entry.welcome }}
</code></pre>

<p>To get Live Preview working with your Chapters example, you'd need to somehow make the connection to the <code>entry</code> variable.</p>

<p>What I came up with is this: you still loop through the <code>chapters</code> returned from your <code>craft.entries</code> call. But within the loop you conditionally overwrite the <code>chapter</code> variable in case it matches your current <code>entry</code> EntryModel.</p>

<p>I also replaced <code>getSegment()</code> with <code>getAncestors()</code>, to not rely on any specific paths / routes that might change in the future:</p>

<pre><code>{# Get the top level entry #}
{% if entry.level != 1 %}
    {% set rootEntry = entry.getAncestors().first() %}
{% else %}
    {% set rootEntry = entry %}
{% endif %}

{{ rootEntry.body }}

{% set chapters = rootEntry.children %}
{% for chapter in chapters %}

    {# Bugfix for live preview #}
    {% if chapter.id == entry.id %}{% set chapter = entry %}{% endif %}

    {{ chapter.body }}

{% endfor %}
</code></pre>

CC BY-SA 3.0
2014-12-01T18:54:40.027Z
nailed it! Thanks for rooting this out. I think this qualifies as a bug?
Brian Whitton
CC BY-SA 3.0
2014-12-01T23:53:58.170Z
@noSlouch yeah, maybe it's a bug. But I think it's more likely that this is simply how Live Preview works right now. It definitely qualifies as a feature request though!
carlcs
CC BY-SA 3.0
2014-12-02T06:08:04.553Z
I'll add something to the G+ page
Brian Whitton
CC BY-SA 3.0
2014-12-01T10:21:36.223Z
2014-12-04T08:13:36.720Z
2014-12-04T08:13:36.720Z
carlcs
<p>Is there an undocumented shortcoming of Live Preview? Seems to only work where the entry variable is concerned. </p>

<p>I'm using a Structure section to create pages with "Chapters". The section (let's call it <strong>Areas</strong>) has a Max Level of 2. The idea is that level 1 entries  load a template that calls the content from all of that entry's children.</p>

<p>For instance, Areas looks like this in the CP:</p>

<pre><code>Learning
-- Our Approach
-- Design Patterns
-- etc.
</code></pre>

<p>The front-end works just fine. <code>/areas/learning</code> loads the <code>areas/_entry</code> template where I call all of the entry's children and output their content to the page.</p>

<p>The issue is in Live Preview when editing a child entry, such as <strong>Our Approach</strong>. It looks like Live Preview only likes using the provided <code>entry</code> variable, but will not update anything nested, found in a loop, or otherwise loaded into the template's context. </p>

<p>For instance, this simplified template code, while rendering as expected, does not update in Live Preview:</p>

<pre><code>{% if craft.request.isLivePreview %}
    {% set myEntry = craft.entries.slug(craft.request.getSegment(2)).first() %}
{% endif %}

{% set chapters = myEntry.children %}

{{ myEntry }}
&lt;ul&gt;
{% for chapter in chapters %}
    &lt;li&gt;{{chapter}}&lt;/li&gt;
{% endfor %}
&lt;/ul&gt;
</code></pre>

<p>I renamed the entry variable as per <a href="https://craftcms.stackexchange.com/a/1644/1027">this answer</a>. Thoughts?</p>

<templating><control-panel><live-preview>
Live Preview only works for Entry variable?
# Live Preview only works for Entry variable?

(Asked by: username_0 on 2014-11-25)

Is there an undocumented shortcoming of Live Preview? Seems to only work where the entry variable is concerned. 
I'm using a Structure section to create pages with "Chapters". The section (let's call it Areas) has a Max Level of 2. The idea is that level 1 entries  load a template that calls the content from all of that entry's children.
For instance, Areas looks like this in the CP:
Learning
-- Our Approach
-- Design Patterns
-- etc.

The front-end works just fine. /areas/learning loads the areas/_entry template where I call all of the entry's children and output their content to the page.
The issue is in Live Preview when editing a child entry, such as Our Approach. It looks like Live Preview only likes using the provided entry variable, but will not update anything nested, found in a loop, or otherwise loaded into the template's context. 
For instance, this simplified template code, while rendering as expected, does not update in Live Preview:
{% if craft.request.isLivePreview %}
    {% set myEntry = craft.entries.slug(craft.request.getSegment(2)).first() %}
{% endif %}

{% set chapters = myEntry.children %}

{{ myEntry }}

{% for chapter in chapters %}
    {{chapter}}
{% endfor %}


I renamed the entry variable as per this answer. Thoughts?

**Tags:** templating, control-panel, live-preview


---

## 2 answers

### Answer by username_1 on 2014-12-03. Score: 4 | Accepted answer

We just changed this behavior in [Craft 2.3.2616](http://buildwithcraft.com/updates#build2616):

> Live Preview and Share links will now show the unpublished entry/category changes wherever the entry/category are being referenced in the templates (even areas where the entry/category was fetched from the database).

So now Live Preview (and Share links) should work as expected for you.

> **Comments:**
> **username_2**: I like this kind of answers!  
> **username_0**: this is amazing! thanks for listening Brandon :). Sorry @username_2, but I'll have to change the correct answer to this one, since I went back and updated my template to reflect this change.  
> **username_2**: No way, @noSlouch! Now that I was so creative and found a solution for this, I insist that YOU stick to it.  

---

### Answer by username_2 on 2014-12-01. Score: 2

Update:
Thanks to P&T this workaround is not necessary any more with Craft 2.3.2616!

This was my temporary solution / bugfix:

I think you're right, Live Preview seems to only update if changes to the automatically provided entry EntryModel are detected.
So this causes problems with Live Preview:
{# Get `entry` manually #}
{% set home = craft.entries.section('home').first() %}
{{ home.welcome }}

while this works fine:
{{ entry.welcome }}

To get Live Preview working with your Chapters example, you'd need to somehow make the connection to the entry variable.
What I came up with is this: you still loop through the chapters returned from your craft.entries call. But within the loop you conditionally overwrite the chapter variable in case it matches your current entry EntryModel.
I also replaced getSegment() with getAncestors(), to not rely on any specific paths / routes that might change in the future:
{# Get the top level entry #}
{% if entry.level != 1 %}
    {% set rootEntry = entry.getAncestors().first() %}
{% else %}
    {% set rootEntry = entry %}
{% endif %}

{{ rootEntry.body }}

{% set chapters = rootEntry.children %}
{% for chapter in chapters %}

    {# Bugfix for live preview #}
    {% if chapter.id == entry.id %}{% set chapter = entry %}{% endif %}

    {{ chapter.body }}

{% endfor %}

> **Comments:**
> **username_0**: nailed it! Thanks for rooting this out. I think this qualifies as a bug?  
> **username_2**: @noSlouch yeah, maybe it's a bug. But I think it's more likely that this is simply how Live Preview works right now. It definitely qualifies as a feature request though!  
> **username_0**: I'll add something to the G+ page  

---

