0

{% 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?

Jake Cattrall
  • 297
  • 1
  • 7

1 Answers1

3

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.

Lindsey D
  • 23,974
  • 5
  • 53
  • 110
  • 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.

    – Jake Cattrall May 26 '15 at 15:30