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

How i can set default image if image not found

Started by Muut Archive 10 years ago · 1 replies · 404 views
10 years ago

if image not uploaded form admin in this case i want to set default image

{% set first_image = ps.media.images|first %}
{{ first_image.cropZoom(900,300).html() }}

10 years ago

Assumed default.jpg is in the user/pages/images folder, you can do something like this:

TWIG
{% set firstimage = ps.media.images|first %}
{% set defaultimage = page.find('/images').media['default.jpg'] %}

{% if firstimage %}
  {{ firstimage.cropZoom(900,300).html() }}
{% else %}
    {{ defaultimage.cropZoom(900,300).html() }}
{% endif %}

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1362 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 2959 9 years ago
Archive · by Muut Archive, 9 years ago
3 1124 9 years ago