1

This was working fine previously and not sure what triggered the error. Any idea how to resolve issue?

{% for block in entry.servicesItems.type('images') %}
    <div class="col">

        {# grab the first image #}
        {% set image = block.image.first() %}

        {# link to the full sized version #}
            <a href="{{ image.getUrl }}">
        {# generated the transformed thumbnail version #}
            <img src="{{ image.getUrl('servicesImageCrop')}}" alt="{{ block.alt }}" width="{{ image.getWidth('servicesImageCrop') }}" height="{{ image.getHeight('servicesImageCrop') }}">
            <div id="lightbox-title">
                <h2>{{ block.imageTitle }}</h2>
                <p>{{ block.imageContent }}</p>
            </div>
        </a>
    </div>
{% endfor %}
4
  • Figured it out, it was actually caused by an empty matrix block in an entry. Any idea how to prevent this from page error if user accidentally does this?
    – frshjb373
    Nov 13, 2014 at 21:25
  • You can check if it is defined first using {% if block.image.first() %}...{% endif %} or {% if image %}...{% endif %}. Nov 13, 2014 at 21:56
  • 1
    Can you add that as an official answer, @frshjb373?
    – Brad Bell
    Nov 13, 2014 at 23:28
  • If you found an answer to your question, you can post it :) Answering own questions is not discouraged.
    – nicael
    Nov 15, 2014 at 18:18

1 Answer 1

2

You can just test if image is defined first using:

{% set image = block.image.first() %}
{% if image %}
    <a href="{{ image.getUrl() }}">...</a>
{% endif %}

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.