0

I'm new to Craft and I'm stumbling at the first hurdle for Craft 3

I'm getting "Variable "entry" does not exist." and I'm certain it's something so simple I'm missing.

Case:

  • Install craft 3 via composer
  • Add a Single section called "Homepage" (URI: "/" | template: "index")
  • Add "templates/index.twig" - test it with basic markup; displays correctly
  • Add plain text field to homepage section ("homepageHeader")
  • Fill out homepageHeader in control panel and save.
  • Change template to literally only "{{entry.homepageHeader}}"
  • Error above after page refresh

I must be missing something VERY simple. What is it?

  • In order to test if you are in the correct template, you can open the homepage entry directly in your cp list (with the world icon) do you receive a route not found or template does not exists exception when you do that? Note: in order to set an entry as homepage you should leave the uri blank => no / – Robin Schambach Mar 8 '18 at 18:48
  • Changing the URI to blank was the key! Feel free to add as an answer and I'll mark it. Thanks! – Mr DC Mar 9 '18 at 11:18
2

In order to set an entry as your "homepage" entry you have to leave the uri in the section completely blank. It does not work when you insert a / because this route does not fetch the correct element thus Craft is not able to provide the entry variable in your twig template

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.