{% import _self as mcr_home %}

is throwing

Object of class Craft\ElementCriteriaModel could not be converted to string

How is this possible and how do I fix it?

  • Any name collisions? With "import", or "_self" or "mcr_home"? May 22 '15 at 17:39
  • Can you enable devMode, reproduce the error then share the full stack trace so we can see where the error originates from?
    – Brad Bell
    May 22 '15 at 19:32

In short, those two have nothing to do with each other. What's more likely is that the error is being triggered by the imported script. It's possible that your stack trace is just giving you a red herring by pointing to the import itself.

In your Twig code:

import pulls in a macro (or macros).

_self just means "this template file".

"mcr_home" is just how you're referring to your imported macro(s).

In the error message:

An ElementCriteriaModel is simply a model representing a Craft content search.

"could not be converted to string" is telling you that the model cannot be read as a string.

Obviously there is no correlation there. Take a closer look at the macro(s) you are importing... I'm certain you will find an ElementCriteriaModel which is attempting to be used as a string.

  • There was a lot of code in the template so the error pointing to that line really threw me off. Turns out it was something in the template that it was extending. {% extends "_layout" %} Seems strange that the error was so utterly useless. May 26 '15 at 15:30

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.