Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

`image in page.media.images` Problem/Question

Started by Muut Archive 10 years ago · 2 replies · 508 views
10 years ago

In the following:

TWIG
{% for image in page.media.images | slice(0,1) %}

      {% if image is not null %}

         {{ image.cropZoom(500, 500).html() }}     

      {% else %}

         <img src="{{ theme_url }}/css/images/square-placeholder.png">

      {% endif %}

{% endfor %}

I was expecting image to be null if there were no images attached to the page. No? Advice appreciated because no matter how I word the if the image is always something. How do I dump the variable or array?

10 years ago

if there are no images available, then the for loop is not even entered. you would need to check to see if page.media.images is empty or length == 0.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1368 9 years ago
Archive · by Muut Archive, 9 years ago
2 940 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2960 9 years ago
Archive · by Muut Archive, 9 years ago
3 1125 9 years ago