1

So, the subject. I am currently working with customer of craftcms v2. I am setting up Structure Section where I want to add Entry Type for index listing of items and add some items in list.

So, here is my setup:

  1. Section: https://i.stack.imgur.com/quVtb.jpg
  2. Section EntryType: https://i.stack.imgur.com/RCglJ.jpg
  3. Field Settings tab: https://i.stack.imgur.com/FCC8I.jpg
  4. Field Layout tab: https://i.stack.imgur.com/xK4QY.jpg
  5. Entry Example: https://i.stack.imgur.com/K0GFw.jpg

I have 3 Entries added. I made this setup exactly the same as was for same page type (Structure Section too). But page I did throws error as in subject title.

I've googled and found that the key for 'entry' object in template using is to check this option in Section settings:

'Entries in this section have their own URLs'

I found that in this article: https://straightupcraft.com/articles/the-craft-entry-variable

So, what may be the problem? This option is checked. Also exactly the same page (called Features) works well! It's kind of magic I think.

Simple code in template raises the error: https://pastebin.com/fjqeb1LT I am using template in 'app/craft/templates/reviews/index.twig' folder.

4
  • Can you paste the complete code from index.twig where the "entry" is created?
    – phaetons
    Jan 22, 2019 at 17:24
  • What URL are you going to when you get this error? Jan 22, 2019 at 17:53
  • @phaetons yes, here it is: pastebin.com/CH6RgGpC
    – Clark
    Jan 23, 2019 at 10:07
  • @BrandonKelly url is localhost/reviews
    – Clark
    Jan 23, 2019 at 10:07

1 Answer 1

2

That entry variable will only be predefined for the template when you go to one of your entry’s URLs.

Your section’s Entry URL Format for top-level entries is {slug}, and your entry’s slug is qweasdzxc, so that would make your entry’s URL <site-url>/qweasdzxc (http://localhost/qweasdzxc).

If you change your section’s top-level Entry URL Format to reviews/{slug} instead of just {slug}, then the entry’s URL will become <site-url>/reviews/qweasdzxc.

When you go to <site-url>/reviews, you’re just accessing the reviews/index.twig template directly, so the entry variable was never defined, which is causing the error you’re getting.

1
  • Thanks! Strange but I saw calls and selections from entry variable from index.twig template (related to similair section) from other devs, so I was confused.
    – Clark
    Jan 23, 2019 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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