How pass an ElementModel to a Macro in Twig I'm trying to pass an AssetModel into a twig macro but all I'm getting is:

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


Is there any way to define my twig macro variable to be an object instead of a string?

This is my macro

{% macro item(thumbnail) %}
    {% if thumbnail %}
        &lt;img src="{{ thumbnail }}"/&gt;
    {% endif %}
{% endmacro %}


This is my template

{% import "macros/grid.html" as grid %}

{% for entry in craft.entries.section('handle') %}
    {{ grid.item(entry.image) }}
{% endfor %}


entry.image is an Asset field
I see a few problems. The first is that {{ grid.item(entry.image) }} is actually an ElementCriteriaModel (i.e. which behaves like an array of images) and not an ElementModel (i.e. a single image), even if only one image is defined. To get the first image you can use entry.image.first or entry.image[0].

The second problem is that in your macro, &lt;img src="{{ thumbnail }}"/&gt; is trying to set the url string using the whole ElementModel (or in your case the ElementCriteriaModel). Instead use: {{ thumbnail.url }}

{% macro item(thumbnail) %}
    {% if thumbnail %}
        &lt;img src="{{ thumbnail.url }}"/&gt;
    {% endif %}
{% endmacro %}

{% from _self import item %}

{% for entry in craft.entries.section('handle') %}
    {{ item(entry.image.first) }}
{% endfor %}


Update: If on the other hand, for some reason you want to pass the ElementCriteriaModel then you just need to handle it appropriately in the macro:

{% macro item(thumbnail) %}
    {% if thumbnail.first %}
        &lt;img src="{{ thumbnail.first.url }}"/&gt;
    {% endif %}
{% endmacro %}

{% from _self import item %}

{% for entry in craft.entries.section('handle') %}
    {{ item(entry.image) }}
{% endfor %}


As a side note — keep in mind that the macro can also exist in the same template and imported using _self.