2

I'm new to Craft CMS dev and I'm trying to create a template using Twig and I'm getting this error: Craft\EntryModel and its behaviors do not have a method or closure named "Case Studies"

I have a reference in the view file:

{% for entry in entry.caseStudies %}

I'm assuming there's a config file or somewhere I can add this to the EntryModel but I'm not sure where this is in the default Craft installation. Any suggestions are welcome.

Thanks

  • You do not need to add anything to the model to access field properties/values — craft handles all of this for you. You may want to double check that the field caseStudies is defined (and spelled correctly), and that it has been added to the field layout of the entry in question. – Douglas McDonald Mar 31 '16 at 17:00
  • What type of field is caseStudies and how are you defining the initial entry? You'll probably want to rename it to {% for anythingBesidesEntry in entry.caseStudies %} so as not to clobber the original entry variable name. – Brad Bell Mar 31 '16 at 21:48
  • Thanks I think my understanding of the template system is a bit wrong, If I don't add field properties/values and sections in the model then where to I define them? – Ross Apr 4 '16 at 11:43
2

Welcome Ross! If you have 'Case Studies' as a Section and not a field, try changing your syntax to:

{% for entry in craft.entries.section('caseStudies').find() %}

    {{ entry.title }}
    ...

{% endfor %}

Here's an updated example, showing an additional custom field...

{# Find all Entries in the Case Study section #}
{% for entry in craft.entries.section('caseStudies').find() %}

    {# Display the entry's Title #}
    <h2>{{ entry.title }}</h2>

    {# Display the contents of the Intro Summary (plain text field) #}
    <p>{{ entry.introSummary }}</p>

{% endfor %}
  • Thanks Matt, I think my understanding of the template system is a bit wrong. I thought that if I added entry.caseStudies to the template then it would give the option for that field in the backend. Are there any guides/docs available on how to add Sections and Fields to templates? – Ross Apr 4 '16 at 11:42
  • The contents of a custom field are retrieved using tags WITHIN the for-loop. e.g. {{ entry.title }}. Check out: craftcms.com/docs/templating/craft.entries. Each field-type has a different syntax for rendering or making use of it's contents: craftcms.com/docs/fields – Matt P Apr 4 '16 at 14:37
  • Thanks - But is it possible to create custom fields like {{ entry.variable }} – Ross Apr 5 '16 at 19:18

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.