I'm following the documentation 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.


Craft automatically includes the entry variable if the slug matches the url:

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:

{% if entry is not defined %}
    {% set entry = craft.entries.section('contact-us').first() %}
    {# Fetch single which has 'contact-us' as a handle #}
{% endif %}
  • 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() %} Jul 29 '14 at 18:43
  • 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?
    – Victor In
    Jul 29 '14 at 18:46
  • 1
    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. Jul 29 '14 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.