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://imgur.com/a/afXBU4M
  2. Section EntryType: https://imgur.com/a/ugkEkGh
  3. Field Settings tab: https://imgur.com/a/efAe0Kp
  4. Field Layout tab: https://imgur.com/a/4FuZcAZ
  5. Entry Example: https://imgur.com/a/KIxOdbO

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.

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.

  • 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 at 13:19

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.