<blockquote>
<p>I get an error Variable &quot;entry&quot; does not exist.</p>
</blockquote>
<p>This means that when you're trying to use <code>entry.faqs.all()</code>, the <code>entry</code> variable doesn't exist, so you get this error. <code>entry.faqs</code> accesses a field named <code>faq</code> of the current entry. So you will get different results on different pages.</p>
<p>If the <code>entry</code> variable doesn't exist, this usually means that the current route does not belong to an entry at all. It might be a <a href="https://craftcms.com/docs/4.x/categories.html" rel="nofollow noreferrer">category</a> or a <a href="https://craftcms.com/docs/4.x/routing.html" rel="nofollow noreferrer">custom route</a>, both of which don't set an <code>entry</code> variable by default.</p>
<p>If you want to display FAQ entries from a field on the <em>current entry</em>, make sure that you only include that code on templates that belong to entries with that field.</p>
<p>However, if you want to display the <em>same</em> FAQ entries from one specific entry, you need to use an entry query to find that entry. Then you can access the FAQ field from anywhere. For example:</p>
<pre class="lang-twig prettyprint-override"><code>{% set faq_entry = craft.entries()
    .section('my_faq_section')
    .one()
%}
{% set faqs = faq_entry.faqs.all() %}
</code></pre>

CC BY-SA 4.0
2023-02-02T08:38:18.040Z
2023-02-02T08:38:18.040Z
MoritzLost
<p>I have a Faq page with an accordion, and it works perfectly, yet I have two identical pages in the same faq folder with the same exact code but it only works on the <code>index.twig</code> and not on the other two pages. On all the pages I have under the Faq a contact form and on the other two pages there is an extra code for if an error occurs or a success. I did the same principle on my contact page also three pages and two with the success and error code in it.</p>
<p>It goes wrong with this code:</p>
<pre><code>{% for Faqs in entry.faqs.all() %}
    &lt;div class=&quot;card-header&quot;&gt;
        &lt;h4 class=&quot;card-title m-0&quot;&gt;
            &lt;a class=&quot;accordion-toggle&quot; data-bs-toggle=&quot;collapse&quot; data-bs-parent=&quot;#accordion{{count}}&quot; href=&quot;#collapse{{count}}&quot;&gt;
                &lt;i class=&quot;fas fa-users&quot;&gt;&lt;/i&gt;
                {{Faqs.question}}
            &lt;/a&gt;
        &lt;/h4&gt;
    &lt;/div&gt;
    &lt;div id=&quot;collapse{{count}}&quot; class=&quot;collapse show{{count}}&quot;&gt;
        &lt;div class=&quot;card-body&quot;&gt;
            &lt;p class=&quot;mb-0 text-5&quot;&gt;{{Faqs.answers}}&lt;/p&gt;
        &lt;/div&gt;
        {% set count = count+1 %}
    &lt;/div&gt;
{% endfor %}
</code></pre>
<p>I get an error Variable &quot;entry&quot; does not exist, yet the same code works on the index.twig and not on the other two.</p>
<p>And before you think what other code, it is just html underneath the form.</p>
<p>What am I doing wrong, and why does it work with the contact pages and not on the faq pages???</p>

<entry>
Why does the same code work on one page and not on another
# Why does the same code work on one page and not on another

(Asked by: username_0 on 2023-02-01)

I have a Faq page with an accordion, and it works perfectly, yet I have two identical pages in the same faq folder with the same exact code but it only works on the index.twig and not on the other two pages. On all the pages I have under the Faq a contact form and on the other two pages there is an extra code for if an error occurs or a success. I did the same principle on my contact page also three pages and two with the success and error code in it.
It goes wrong with this code:
{% for Faqs in entry.faqs.all() %}
    
        
            
                
                {{Faqs.question}}
            
        
    
    
        
            {{Faqs.answers}}
        
        {% set count = count+1 %}
    
{% endfor %}

I get an error Variable "entry" does not exist, yet the same code works on the index.twig and not on the other two.
And before you think what other code, it is just html underneath the form.
What am I doing wrong, and why does it work with the contact pages and not on the faq pages???

**Tags:** entry


---

## 1 answers

### Answer by username_1 on 2023-02-02. Score: 2

I get an error Variable "entry" does not exist.

This means that when you're trying to use entry.faqs.all(), the entry variable doesn't exist, so you get this error. entry.faqs accesses a field named faq of the current entry. So you will get different results on different pages.
If the entry variable doesn't exist, this usually means that the current route does not belong to an entry at all. It might be a category or a custom route, both of which don't set an entry variable by default.
If you want to display FAQ entries from a field on the current entry, make sure that you only include that code on templates that belong to entries with that field.
However, if you want to display the same FAQ entries from one specific entry, you need to use an entry query to find that entry. Then you can access the FAQ field from anywhere. For example:
{% set faq_entry = craft.entries()
    .section('my_faq_section')
    .one()
%}
{% set faqs = faq_entry.faqs.all() %}


---

