3

I've run into an unexpected situation, where ElementCriteriaModel could not be converted to string.

{% set news = craft.entries.section('news').limit(3) %}
{% for news in news %}
    {% set cover = news.promotionNewsImage %}
    {% if cover|length %}
        {{ cover.getUrl('gtLg') }}
    {% endif %}
{% endfor %}

Any thoughts on that please?

5

Your image input returns and array so you need to reference the first item, even if you only allowed one to be selected.

{% set news = craft.entries.section('news').limit(3) %}
{% for news in news %}
   {% set cover = news.promotionNewsImage %}
   {% if cover|length %}
       {{ cover[0].getUrl('gtLg') }}
   {% endif %}
{% endfor %}
|improve this answer|||||
  • That has solved my problem, only when I run it outside <style type="text/css">@media (min-width: 1200px){.news{code}}</style>. I thought, that neccesary markup will not affect the output. I may post my code here, but I feel like it's another question. What do you say? – Dominik Krulak Oct 30 '15 at 20:01
  • 1
    You may need to post that separately that seems different to what you asked above. – aran Oct 30 '15 at 21:03

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.