1

Now I've run into a really odd issue. I've got a hero include that is working elsewhere on the site, but on this one single it's not working at all. On a working "Single" the code is this

{% extends "_layout" %}

{% block content %}


{% include '_includes/hero'
  with {
    imageName : 'page-hero-about',
    className : 'about',
    imageAlt  : 'Photo of store front',
    findStore : false,
    leadCols  : 'col-md-6',
    leadClass : 'lead'
  }
%}

And on the other non-working single the code is this:

{% extends "_layout" %}

{% block content %}

    {#{% set entry = craft.entries.id(72) %} #}

    {% include '_includes/hero'
      with {
          imageName : 'page-hero-mission',
          className : 'mission',
          imageAlt  : 'Teaching people to read',
          findStore : false,
          leadCols  : 'col-md-9',
          leadClass : ''
     }
%}

On the non working page if I don't set the entry id I get a variable "entry" does not exist (though this is not needed on the working single). However once I do set that I get this error Object of class Craft\ElementCriteriaModel could not be converted to string Have googled but can't seem to find anything. Also the code is pretty much identical so am at a loss

2

In your current code, the entry variable is actually an instance of ElementCriteriaModel, which is probably the reason you're getting errors.

In order to set entry to an actual EntryModel, you'll need to add a call to first():

{% set entry = craft.entries.id(72).first() %}
...
  • That solves it. Thank you. But why does the other template not require me to set the entry? – CreateSean Jan 18 '17 at 19:18
  • I'm guessing that the other template is the Entry Template for that particular Single section, in which case Craft will automatically populate the entry variable with the correct entry for you. Perhaps you can set the not-working template as the Entry Template for your other Single … in which case the above isn't neccessary. Just pop open the relevant Section via Settings -> Sections, and add the appropriate template path to "Entry Template" field. – Mats Mikkel Rummelhoff Jan 18 '17 at 19:25

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.