Answers.Body: <p>The <code>Twig Runtime Error – Twig\Error\RuntimeError Variable &quot;entry&quot; does not exist.</code> typically happens when the variable has not been declared on the twig file getting pulled.</p>
  <p>Its hard to suggest a solution without screenshots or code examples but I <em>think</em> if you check you have declared your entry variable in the <code>homepage.twig</code> file it should resolve.</p>
  <p>Another reason why this error occurs is if the first instance of the variable is declared within an <code>if</code> or <code>for</code> statement and called again after said statement. The error happens during this time when the <code>if</code>/<code>for</code> is false and doesn't run, therefor the file never sees the variable created. If this is the case I suggest creating an empty <code>set entry = &quot;&quot;</code> before your <code>if</code>/<code>for</code> statement.</p>
  <p>Below are some very high-level examples of what would cause this error and what would not.</p>
  <hr />
  <p><strong>Example that would cause error:</strong></p>
  <pre><code>//head.twig
  {% set entry = value %}
  
  //homepage.twig
  {% extends &quot;head.twig&quot; %}
  {{ entry }}
  </code></pre>
  <hr />
  <p><strong>Example that would cause error:</strong></p>
  <pre><code>//homepage.twig
  {% if x = y %}
     {% set entry = value %}
  {% endif %}
  
  {{ entry }}
  </code></pre>
  <hr />
  <p><strong>Example that would not cause error:</strong></p>
  <pre><code>//homepage.twig
  {% set entry = '' %}
  
  {% if x = y %}
     {% set entry = value %}
  {% endif %}
  
  {{ entry }}
  </code></pre>
  <p>If you fixed this already I am curious to know what you did. Hopefully my assumption is found helpful</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-01-12T00:10:21.710Z
Answers.LastActivityDate: 2024-01-12T00:10:21.710Z
Answers.UserDisplayName: kelly
Body: <p>I'm a newbie with Craft CMS and just setup my templates. I got multiple .twig files for six pages. If I load my homepage &quot;from scratch&quot; my entries are shown as I want them to. But if I click on a link from another page back to my homepage, the entries are not loaded anymore and I get an error.</p>
  <p>Twig Runtime Error – Twig\Error\RuntimeError
  Variable &quot;entry&quot; does not exist.</p>
  <p>How do I fix this? I don't know if you would need more information to help. Just let me know.
  Thanks for the help in advance! And sorry for being a newb.</p>
  
Tags: <entries><entry><error><link>
Title: Linked pages can't load entry-variable
ThreadText: # Linked pages can't load entry-variable
  
  (Asked by: username_0 on 2023-12-15)
  
  I'm a newbie with Craft CMS and just setup my templates. I got multiple .twig files for six pages. If I load my homepage "from scratch" my entries are shown as I want them to. But if I click on a link from another page back to my homepage, the entries are not loaded anymore and I get an error.
  
  Twig Runtime Error – Twig\Error\RuntimeError
  Variable "entry" does not exist.
  
  How do I fix this? I don't know if you would need more information to help. Just let me know.
  Thanks for the help in advance! And sorry for being a newb.
  
  **Tags:** entries, entry, error, link
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-01-12. Score: 1
  
  The `Twig Runtime Error – Twig\Error\RuntimeError Variable "entry" does not exist.` typically happens when the variable has not been declared on the twig file getting pulled.
  
  Its hard to suggest a solution without screenshots or code examples but I *think* if you check you have declared your entry variable in the `homepage.twig` file it should resolve.
  
  Another reason why this error occurs is if the first instance of the variable is declared within an `if` or `for` statement and called again after said statement. The error happens during this time when the `if`/`for` is false and doesn't run, therefor the file never sees the variable created. If this is the case I suggest creating an empty `set entry = ""` before your `if`/`for` statement.
  
  Below are some very high-level examples of what would cause this error and what would not.
  
  ---
  
  **Example that would cause error:**
  
  ```
  //head.twig
  {% set entry = value %}
  
  //homepage.twig
  {% extends "head.twig" %}
  {{ entry }}
  
  ```
  
  ---
  
  **Example that would cause error:**
  
  ```
  //homepage.twig
  {% if x = y %}
     {% set entry = value %}
  {% endif %}
  
  {{ entry }}
  
  ```
  
  ---
  
  **Example that would not cause error:**
  
  ```
  //homepage.twig
  {% set entry = '' %}
  
  {% if x = y %}
     {% set entry = value %}
  {% endif %}
  
  {{ entry }}
  
  ```
  
  If you fixed this already I am curious to know what you did. Hopefully my assumption is found helpful
  
  
  ---
  
  