Comparing a metadata value to a Get query string value


(Hugh McMaster) #1

Matrix Version: 5.3.4.0

Hi everyone,

I’ve got an asset listing that displays varous metadata fields (title, author, year of publication) for some PDF files I have on Squiz. I’d like to filter this list based on a given year.

So far, I’ve managed to filter the list by hard-coding in a year.

%begin_asset_metadata_year^eq:2016%
<li>%asset_metadata_title</li>
%end_asset%

This works well, but I’d like to handle this dynamically. I’ve tried using the following line:

%begin_asset_metadata_year^eq:{globals_get_year}%

but the asset listings page doesn’t display anything.

Is there some kind of precedence in evaluation that causes the conditional to evaluate to false? Or is there another way to achieve what I’m after?

In case it’s important, the global year value is valid. It displays when I add %globals_get_year% into the page.

Thank you.


(Peter McLeod) #2

Hi
Try adding the replace_keywords modifer:
https://matrix.squiz.net/manuals/keyword-replacements/chapters/keyword-modifiers#Using-Keyword-Replacements-as-Argument-Values
Thanks
Peter


(Hugh McMaster) #3

Thanks for the link, Peter.

I see now that because I’m using 5.3.4.0 I need to use the replace_keywords modifier.

Unfortunately, adding replace_keywords doesn’t get me any further, although it does display all PDF files on the listing.

%begin_asset_metadata^replace_keywords:eq:{globals_get_year}%

I found Pass a date variable into an asset listing this morning, which seems to describe the same issue.


(Bart Banda) #4

Contrary to what I believe previously in my first comment on Pass a date variable into an asset listing, it’s expected behaviour.

%asset_x% based keywords in the type formats of an asset listing get evaluated separately to %globals_X% keywords, so that kind of keyword comparison won’t work because %globals_X will only get evaluated at the top level and at the end of the page generation in Matrix.

This explains it a bit: https://matrix.squiz.net/manuals/concepts/chapters/server-side-javascript#processing-order

Until you get on 5.4, the only way to do this for now unfortunately is to use CSS to show/hide it.

Alternatively, you could try doing something like this:

%asset_metadata_year^replace_keywords:eq:{globals_get_year}:<li>{asset_name}</li>:%

But, a stored search page that filters the list on a stored search value instead would remove the need for keyword modifiers and would only list the assets you need.


(Hugh McMaster) #5

Now it all makes sense. The order of evaluation prevents this from working as I expected.

I didn’t get any further with your keyword modifier suggestion, so I’ve built a simple search page that does the job.
And as you say, it removes a lot of the complexity of the asset listing solution.

Thanks.