If asset_metadata OR asset_metadata exists


#1

Matrix Version:5.4.5.1

Is there a pattern for checking if several asset_metadata fields have content? I have found examples of how to check if an asset_metadata field equals multiple things, but not how to do something like

if (asset_metadata_thing1 OR asset_metadata_thing2) {
show thing that should be shown if either exists
}

OR

if (asset_metadata_thing1 AND asset_metadata_thing2) {
show thing that should be shown if both exist
}


(Hugh McMaster) #2

Matrix keywords have limited scope for boolean logic as found in most other programming languages.

You can simulate OR logic with the empty keyword modifier.

%begin_asset_metadata_thing1^empty:{asset_metadata_thing2}%
...
%end_globals%

AND logic can only be achieved via nesting, which becomes complex with multiple levels, so I always recommend writing the begin and end keywords for each level before doing anything else.

@Bart, are there any plans to improve boolean logic?


Conditional "or"
(Bart Banda) #3

Hey, no plans to add that to keywords as this is most commonly implemented via SSJS.

So for example, you would do something like:

<script runat="server">
if('%asset_metadata_foo%' == 'foo' || '%asset_metadata_bar%' == 'bar'){
  print('foo or bar')
}
</script>