<p>The problem is that you're using the <code>only</code> keyword when including the <code>post-blocks.twig</code> partial template, in your <code>blog/_entry.html</code> template:</p>
<pre><code>{% include &quot;_includes/post-blocks.twig&quot; with { blocks: entry.postContent.all() } only %}
</code></pre>
<p>The <code>only</code> keyword instructs Twig to <em>not</em> make the global context (i.e. all the variables in the upper scope) available to the included template. Hence, the included <code>post-blocks.twig</code> template doesn't have access to the <code>entry</code> variable, which is defined in the upper scope relative to that included template.</p>
<p>To fix the issue, either make the global context (including the <code>entry</code> variable) available to the included template by removing the <code>only</code> keyword:</p>
<pre><code>{% include &quot;_includes/post-blocks.twig&quot; with { blocks: entry.postContent.all() } %}
</code></pre>
<p>...or explicitly make the <code>entry</code> variable available to the included template, by including it alongside the <code>blocks</code> variable in context object passed using the <code>with</code> keyword:</p>
<pre><code>{% include &quot;_includes/post-blocks.twig&quot; with { 
    blocks: entry.postContent.all(),
    entry
} only %}
</code></pre>
<p>On a general note; I don't know if you have a good reason to use <code>only</code> in this case, but generally it's only needed to avoid variable collisions and similar problems. It can be a matter of preference too; some developers who like to code very defensively will prefer to always include it, alongside any and all variables that they explicitly want the included template to have access to.</p>

CC BY-SA 4.0
2023-04-27T12:37:22.117Z
Thanks for the good explanation. We are going to try and see. Thanks again
Ron Cooper
CC BY-SA 4.0
2023-04-27T12:26:42.163Z
2023-04-27T12:26:42.163Z
Mats Mikkel Rummelhoff
<p>We just installed the CMS and like it very much. On the other hand while following the basic tutorial we seem to get the error &quot;Variable &quot;entry&quot; does not exist.&quot; on the most simple piece of code. Can someone please see and help us? We tried to just make a simple blog entry following the tutorial on the craft CMS website.</p>
<p>...</p>
<pre><code>&lt;div class=&quot;my-8&quot;&gt;
  {% for block in entry.postContent.all() %}
    &lt;div class=&quot;my-4&quot;&gt;
          {% if block.type == 'text' %}
        {{ block.text }}
      {% elseif block.type == 'image' %}
        {% for image in block.image.all() %}
          &lt;img src=&quot;{{ image.url }}&quot; alt=&quot;{{ image.title }}&quot; /&gt;
        {% endfor %}
      {% endif %}
    &lt;/div&gt;
  {% endfor %}
&lt;/div&gt;
</code></pre>
<p>...</p>
<p>Gives error <a href="https://speedwindsurfing.nl/blog/dit-is-een-blog-post" rel="nofollow noreferrer">https://speedwindsurfing.nl/blog/dit-is-een-blog-post</a></p>
<p>The code is in templates/_includes/post-block.twig as mentioned in the howto. <a href="https://craftcms.com/docs/getting-started-tutorial/configure/section.html#create-a-category-group" rel="nofollow noreferrer">https://craftcms.com/docs/getting-started-tutorial/configure/section.html#create-a-category-group</a></p>
<p>Hope you can help us out</p>

<templating><entry><error><post>
Variable entry does not exist on blog post
# Variable entry does not exist on blog post

(Asked by: username_0 on 2023-04-27)

We just installed the CMS and like it very much. On the other hand while following the basic tutorial we seem to get the error "Variable "entry" does not exist." on the most simple piece of code. Can someone please see and help us? We tried to just make a simple blog entry following the tutorial on the craft CMS website.
...

  {% for block in entry.postContent.all() %}
    
          {% if block.type == 'text' %}
        {{ block.text }}
      {% elseif block.type == 'image' %}
        {% for image in block.image.all() %}
          
        {% endfor %}
      {% endif %}
    
  {% endfor %}


...
Gives error https://speedwindsurfing.nl/blog/dit-is-een-blog-post
The code is in templates/_includes/post-block.twig as mentioned in the howto. https://craftcms.com/docs/getting-started-tutorial/configure/section.html#create-a-category-group
Hope you can help us out

**Tags:** templating, entry, error, post


---

## 1 answers

### Answer by username_1 on 2023-04-27. Score: 1

The problem is that you're using the only keyword when including the post-blocks.twig partial template, in your blog/_entry.html template:
{% include "_includes/post-blocks.twig" with { blocks: entry.postContent.all() } only %}

The only keyword instructs Twig to not make the global context (i.e. all the variables in the upper scope) available to the included template. Hence, the included post-blocks.twig template doesn't have access to the entry variable, which is defined in the upper scope relative to that included template.
To fix the issue, either make the global context (including the entry variable) available to the included template by removing the only keyword:
{% include "_includes/post-blocks.twig" with { blocks: entry.postContent.all() } %}

...or explicitly make the entry variable available to the included template, by including it alongside the blocks variable in context object passed using the with keyword:
{% include "_includes/post-blocks.twig" with { 
    blocks: entry.postContent.all(),
    entry
} only %}

On a general note; I don't know if you have a good reason to use only in this case, but generally it's only needed to avoid variable collisions and similar problems. It can be a matter of preference too; some developers who like to code very defensively will prefer to always include it, alongside any and all variables that they explicitly want the included template to have access to.

> **Comments:**
> **username_0**: Thanks for the good explanation. We are going to try and see. Thanks again  

---

