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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

How to test equality of two images

Started by Norma White 8 years ago · 2 replies · 364 views
8 years ago

Hi

I am new to TWIG and racing uphill.

I am stymied as I try to test whether two images are the same. One is set by a header variable - value is 'Halloween.jpg'. The other is an item in a loop over the images in the page - value is 'pnhbquark/blog/ Halloween16/Halloween.jpg'. I simply want to display all the images except Halloween.jpg, and whatever I try displays all of the images.
For the test I have tried
{% set raw_url = page.media[lead_image].url %}
{# this yields exactly the same as image #}
{% for image in page.media.images %}
{% if raw_url == image %}
SAME image
{% else %}
{{image}}
{% endif %}
{% endfor %}

{# ALSO tried {% if image|ends_with(lead_image) #}
{# and a few other things #)

Thanks
Norma

8 years ago

Try the following: {% if raw_url == image.url %}

last edited 06/27/18 by pamtbaau
8 years ago

Gee thanks! How do you get to know all this stuff?

Another point: this line of code
{% set raw_url = page.media[lead_image].url %}

failed when I had lead_image: Halloween2017.jpg
I had to put quotes around the filename. I was lucky because the other test files just happened to be sluglike.

Thanks again
Norma

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 74 6 hours ago
General · by pamtbaau, 12 hours ago
1 47 11 hours ago
General · by Andy Miller, 24 hours ago
0 44 24 hours ago
General · by Marcel, 12 months ago
6 346 5 days ago
General · by Duc , 5 days ago
3 39 5 days ago