If asset_metadata OR asset_metadata exists


Matrix Version:

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


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.


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?

(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')