Conditional "or"


(paul walker) #1

Hi Folks
I am trying to display content based on either one and/or two conditions being true -
basically if either X AND/OR Y are true display Z else display nothing

%begin_asset_X%
AND/OR
%begin_asset_Y%
Z - Display this if either true
%else_asset%
Nothing to see here
%end_asset%

I have looked through forums but have not found anything that appears to address this
Sorry, I’m tired, could have missed something obvious!!

Any suggestions helpful
Cheers


(Hugh McMaster) #2

This really depends on what sort of asset data is getting returned by those keywords, and whether you’re planning on doing something different if both X and Y are true, instead of just one or the other.

For your use case, AND/OR is the same as OR, if the subsequent code path is the same.

If you’re using metadata or something that returns a string (or empty string), then you could try one of the suggestions in If asset_metadata OR asset_metadata exists


(paul walker) #3

Hi Hugh - thank you for your response

No asset data is being returned - it is purely to display some html if either one, od both of the conditions is true.
I will take a look at the link you have posted

paul


(Bart Banda) #4

What version are you on?

If you want to have multiple “begin” conditions, you need to use the following format:

%begin_asset_X%
   AND/OR
%else_begin_asset_Y%
   Z - Display this if either true
%else_asset%
   Nothing to see here
%end_asset%

See more at https://matrix.squiz.net/manuals/keyword-replacements/chapters/conditional-keywords#undefined_using-conditional-keywords

Alternatively you could use SSJS to do you logic in JS which might be easier.


(paul walker) #5

Hi Bart - thank you for your response
We are using version v5.5.6.4

Using the coding above;
if X and Y are true “And / Or” displays
If X is true and Y is false “And / Or” displays
If X is false and Y is true “Z” displays
If both X and Y are false “Nothing to see here” displays

I think I may have to explore using JS

cheers - Paul


#6

You can do OR logic with an else by doubling up your content, in this case Z.

%begin_asset_X%
Z
%else_begin_asset_Y%
Z
%else_asset%
Nothing to see here
%end_asset%

To prevent maintenance issues, the HTML content for Z could be in another asset, or a metadata field, or an SSJS variable.


(paul walker) #7

Thanks for all your responses folks
Finally went with ssjs ( as suggested by @Bart)
p