Keyword modifier to know if Image has a variety


(Nic Hubbard) #1

Matrix Version: 5.4.3.1

We have been uploading high resolution Image varieties since 2013, but before that our News images did not have this image variety. I am wanting to use a keyword modifier to check if this variety exists, if it does not just use the regular image url.

So far I am struggling to get anything to work. I have tried:

%image_v_2x_url^empty:EMPTY%
%image_v_2x_url^charcount^eq:0:{asset_url}%

Neither of these work if the image does not have a variety called 2x.

Note: I have considered using a Batch Trigger to create an image variety for the images that are missing it, but since it is upscaling it looks horrible and pixelated.

Any ideas on how I can solve this?


(Douglas (@finnatic at @waikato)) #2

I tend to use a conditional keyword on type formats to check if an image variety exists - e.g. checking the value of %asset_thumbnail_v_<variety_name>_width% - to see if it’s the correct size

Not sure, but have you tried:

%image_v_v2_width^eq:$width%

where $width is whatever you’d expect it to be, if you have uniform image dimensions in use?


(Bart Banda) #3

Are you printing the variety of the thumbnail image asset assigned to the News Item? And if so, how and where are you printing it? In the Paint Layout for the News Item?

If you are printing the image variety of the thumbnail asset on the PL of the News Item, you would need to use the %asset_thumbnail% keyword right?

So what Douglas said, something like:

%begin_asset_thumbnail_v_<variety_name>%
  %asset_thumbnail_v_<variety_name>%
%else_assset%
  %asset_thumbnail%
%end_assset%

(Tbaatar) #4

The begin, else and end is the method i use and it works really well.

If the image variety keywords are different, you can use the Contains, EQ with these conditions.


(Nic Hubbard) #5

That worked. Thanks!


#6

Yoink! @rugi this would be great


(Mark Nearhos) #7

My experience is that this only works if the thumbnail only has one image variety.

The condition only seems to evaluate if there is an image variety, not what the variety is. (ie it evaluates the part %begin_asset_thumbnail_v but not the _<variety_name>)

I’ve been testing with:

%begin_asset_thumbnail_v_v3%
	<p>Show variety 3</p>
	%asset_thumbnail_v_v3%
%else_begin_asset_thumbnail%
	<p>Show thumbnail</p>
    %asset_thumbnail%
%else_asset%
	<p>No thumbnail</p>
%end_asset%

If the asset has:

  • No Thumbnail, it evaluates correctly displaying No Thumbnail
  • A thumbnail with no varieties, it evaluates correctly and displays the Show thumbnail text and the thumbnail
  • A thumbnail with a different variety, (eg v1 or v2 or both, but no v3) it evaluates incorrectly and displays the text Show variety 3 and no image or img element (as there is no v3).
  • A thumbnail with a v3 variety (and others) it evaluates correctly and displays the text Show variety 3 and the v3 image.
Has anyone else come to this conclusion or have I missed something?

Does this have something to do with varieties being shadow assets?

The use case was printing <meta property="og:image"> tags for assets using an og variety and if none use the thumbnail or if neither print no og:image meta tag. It worked fine unless the thumbnail already had another variety.


(Bart Banda) #8

Sounds like a potential bug. What version did you get this in?


(Mark Nearhos) #9

Squiz Matrix v5.4.3.1


(Bart Banda) #10

Was able to replicate in the latest version. Have filed a bug report to get it fixed. Thanks Mark!