I've inherited a Craft-based website, and I'm much more familiar with WordPress, so please pardon the extremely basic question: the homepage for this site uses {% extends "_layout" %} and then references some field data associated with an entry (within "Singles") for "Homepage". I wanted to create a duplicate page to experiment with the template syntax, so I literally copied the contents of index.html into another file of the same name in a folder labeled "preview". Now, if I visit the site via www.site.org/preview I get the following error:

Internal Server Error
Undefined index: entry

I have tried numerous ways of identifying the source of the entries, e.g. set entries but I can't seem to get the field data to output. Of course, if I remove any reference to entry data, the rest of the template renders fine. Why on earth would simply duplicating the homepage file result in the above undefined error? I've tried re-indexing the site assets, clearing caches, etc. Thanks for any assistance here- I'm at my wits' end.


It's because of #2 here: https://docs.craftcms.com/v3/routing.html#dynamic-routes

index.html matches a route (likely you've got a Single section defined in Settings setup to load the index.html template). Because of that, Craft will prepopulate the entry variable for that route in the template.

There currently isn't a route that matches preview/index.html, so Craft doesn't prepopulate the entry variable and you get the error you're seeing.

  • Ah-ha! Thank you- that's extremely useful information. So here's one more, related question- if I have an index.html file in a preview folder as described above, how might I go about defining a route/section that is able to populate the entry variable in the same way as the homepage- is this possible? Or would I need to manually define scope for the variable? Thanks again! *as a side note, I'm seeing there aren't any actual routes defined in settings, however, I do see an entry for Homepage in Settings > Sections —is this how the template is able to pre-populate that variable? – nickpish Jul 11 '19 at 23:36

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.