Check for value of multiple metadata fields in a single Conditional Keyword


(M L Sanders) #1

Matrix Version: 5.3.3.0

I need to set up a Conditional Keyword that will evaluate to true if there are any values supplied on ANY of several metadata fields, yet I can only see the ability to do that for a single field.

Would the following be a possibility for me: set up an additional metadata field and then set its default value to be the value of all of the ‘other’ metadata fields, one after the other. I could then check the value fo the additional field and…voilá!

Has anyone done this sort of thing? I know it would depend on the metadata type to a certain extent (sometimes we’ve set up wysiwyg type metadata and the default has turned out to be (probably our fault) <p></p> which, of course, doesn’t evaluate as ‘empty’) but it might be worth a go, right? No?

thanks, as ever


#2

Easiest is to nest the conditions, it also makes others’ lives easier when they are looking at your solution in distant future. Alternatively you may be able to use (regex) pattern match in the condition depending on what you are looking for.


(M L Sanders) #3

We’re looking to match ANYTHING. We want to print a framework (table, accordion, who cares) IF and ONLY IF any of the metdata contain a value. If none of them contain a value, we don’t want the framework at all!!

Nesting not appropriate in this situation. And the regex in the condition allows a search within a single metadata item only.


(Tim Davison) #4

I’ve done similar, but we didn’t even have access to conditional keywords, had to do it all in keyword modifiers. It’s definitely not elegant. E.g.

%asset_metadata_Field1^append:{asset_metadata_Field2}^append:{asset_metadata_Field3}^replace:term1|term2|term3:###FOUND###^contains:###FOUND###:
  <!-- your code here if found -->
: 
  <!-- your code here if not found -->
^trim%

Explanation:

  • First you append all the metadata fields together into a single ‘string’.
  • Then use replace to regex OR any of the terms you’re looking for
    • if you found any of them put in some unlikely ‘code’, you’re just trying to flag it was found – in this case I used the literal string ###FOUND### - if an author puts that string into the metadata, well, that’s just tough.
  • Then run a contains looking for unlikely code, and if present the first code snippet, otherwise the second
  • trim at the end just cleans it up, not really necessary.

(M L Sanders) #5

Fantastic approach, Tim, ‘not elegant’ indeed. Many thanks for taking the time.