Answers.Body: <p>Craft automatically includes the <a href="http://buildwithcraft.com/docs/templating/entrymodel" rel="noreferrer"><code>entry</code> variable</a> if the <a href="http://buildwithcraft.com/docs/routing" rel="noreferrer">slug matches the url</a>:</p>
  
  <blockquote>
    <p>If the URI matches an entry’s or category’s URI, the
    section’s/category group’s template will get loaded, and the matched
    element will be made available to the template via a pre-populated
    entry or category variable.</p>
  </blockquote>
  
  <p>In your case <code>contact-us</code> gets matched automatically, but <code>contact-us/thank-you</code> does not. This means you have to set <code>entry</code> yourself.</p>
  
  <p>Just add this to the top of your template:</p>
  
  <pre class="lang-twig prettyprint-override"><code>{% if entry is not defined %}
      {% set entry = craft.entries.section('contact-us').first() %}
      {# Fetch single which has 'contact-us' as a handle #}
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-29T18:43:48.463Z
Answers.Text: I had tried that before, I get the following error: `Impossible to access an attribute ("backgroundImage") on a NULL variable ("")`, with this being the code thats erroring: `{% set image       = entry.backgroundImage.first() %}`
Answers.UserDisplayName: Keiron Lowe
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-29T18:46:14.677Z
Answers.Text: If this only happens on the `thank-you` page, it means the `entry` variable is empty. My example works for a Single with the handle `contact-us`. Is your contact page a Single or a Channel/Structure entry?
Answers.UserDisplayName: Victor
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-29T18:49:39.210Z
Answers.Text: You were right, I was getting the slug `contact-us` and the handle `contactUs` mixed up. Now I've got the correct handle in it works.
Answers.UserDisplayName: Keiron Lowe
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-29T18:40:37.310Z
Answers.LastActivityDate: 2014-07-29T18:47:23.550Z
Answers.LastEditDate: 2014-07-29T18:47:23.550Z
Answers.UserDisplayName: Victor
Body: <p>I'm following the <a href="http://sprout.barrelstrengthdesign.com/craft-plugins/forms/docs/examples/adding-a-thank-you-page" rel="noreferrer">documentation</a> to create a thank-you page when the user submits the form.</p>
  
  <p>I have a single created for <code>/contact-us/</code> and I want the user to be redirected to <code>/contact-us/thank-you/</code> when they submit the form. </p>
  
  <p>I have created the route so <code>contact-us/thank-you</code> shows the <code>contact-us</code> template, but when I go to that URL I get a template error saying <code>Variable "entry" does not exist</code>. </p>
  
  <p>So it looks like it's showing the template correctly, but not loading the data from the single.</p>
  
Tags: <entries><routes><singles>
Title: Route breaks Single Entry
ThreadText: # Route breaks Single Entry
  
  (Asked by: username_0 on 2014-07-29)
  
  I'm following the [documentation](http://sprout.barrelstrengthdesign.com/craft-plugins/forms/docs/examples/adding-a-thank-you-page) to create a thank-you page when the user submits the form.
  
  I have a single created for `/contact-us/` and I want the user to be redirected to `/contact-us/thank-you/` when they submit the form.
  
  I have created the route so `contact-us/thank-you` shows the `contact-us` template, but when I go to that URL I get a template error saying `Variable "entry" does not exist`.
  
  So it looks like it's showing the template correctly, but not loading the data from the single.
  
  **Tags:** entries, routes, singles
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-07-29. Score: 9 | Accepted answer
  
  Craft automatically includes the [`entry` variable](http://buildwithcraft.com/docs/templating/entrymodel) if the [slug matches the url](http://buildwithcraft.com/docs/routing):
  
  > If the URI matches an entry’s or category’s URI, the
  > section’s/category group’s template will get loaded, and the matched
  > element will be made available to the template via a pre-populated
  > entry or category variable.
  
  In your case `contact-us` gets matched automatically, but `contact-us/thank-you` does not. This means you have to set `entry` yourself.
  
  Just add this to the top of your template:
  
  ```twig
  {% if entry is not defined %}
      {% set entry = craft.entries.section('contact-us').first() %}
      {# Fetch single which has 'contact-us' as a handle #}
  {% endif %}
  
  ```
  
  > **Comments:**
  > **username_0**: I had tried that before, I get the following error: `Impossible to access an attribute ("backgroundImage") on a NULL variable ("")`, with this being the code thats erroring: `{% set image       = entry.backgroundImage.first() %}`  
  > **username_1**: If this only happens on the `thank-you` page, it means the `entry` variable is empty. My example works for a Single with the handle `contact-us`. Is your contact page a Single or a Channel/Structure entry?  
  > **username_0**: You were right, I was getting the slug `contact-us` and the handle `contactUs` mixed up. Now I've got the correct handle in it works.  
  
  ---
  
  