Nested keyword modifiers?


(David Higley) #1

Hi all

 

Apologies in advance if this is the wrong place for this post and/or numptiness!

 

I am developing a search page and would like this to output a sentence of background text for each search result.  This is easy for calendar events and standard pages which have a metadata description, but a fair proportion of the standard page assets don't have a metadata description and there are a lot of these assets, so it would be a long task to manually add the metadata.

 

I'm using keyword modifiers for other Type Formats (for instance %asset_attribute_description^maxwords:80% for calendar events) but would like to know if it's possible to nest keyword modifiers so I have a single line of code that looks for the metadata and if this is empty, get the first 50 words of the asset contents.

 

The ^empty keyword modiifier looks hopeful and %asset_metadata_Description^empty:asset_contents^maxwords:80% works in my head, but not in Matrix as it just outputs the text 'asset_contents' onto the page.

 

Have tried adapting it with curly brackets, extra % signs and the replace_keywords modifier, but think I may be barking up the wrong tree.

 

So I guess it boils down to two questions:

 

1) Is it possible to nest keyword modifiers and if so, what's the correct 'grammar'?

2) If it's not possible, do you have any ideas for a workaround?

 

Many thanks in advance

 

Cheers

 

David


(Anthony) #2

Hi David,

 

Welcome to the forums! You are thinking along the right lines - but note replace_keywords modifier only came in a relatively recent release so check the manuals page to ensure your system is up to date enough. I stress I havent tested this so I may still get the syntax a bit wrong, but I'd expect something like:

 

%asset_metadata_Description^replace_keywords^empty:{asset_contents}^maxwords:80%

 

I think asset_contents includes the paint layout, so if that has formatting you wouldnt want then you might want to try asset_contents_raw or set up a separate layout and specify it explicitly like asset_contents_paint_X where X is a layout designed to render for search. You might also want to build in the ^striphtml modifier in case there is formatting in the asset contents that you wouldnt want showing in your search results.

 

Tony


(David Higley) #3

Hi Tony and thanks for your help and welcome! I've been lurking for a while, but not needed to post anything up to now...

 

Have tried a few more variants and discovered you can apply mutliple modifiers to the same var e.g.   %asset_contents_raw^maxwords:25^striphtml^trim%, which is fantastic and will come in very handly.

 

It doesn't look like modifiers can handle different dynamic vars within the same statement though, at least on v 4.18.6 ...

 

Thanks again for your help

 

David