If statements


(Gjboyd7) #1

Is it possible to create an if statement in a Paint layout?  

 

For example

 

if (asset_metadata_title exists)

   display this html code and assets keywords

 

elseif (asset_metadata_title exists)

   display this html code and assets keywords

 

else

  display this html code and assets keywords

 

 

I am looking at keyword modifiers, but I don't think they offer this.

 

Any ideas on how this should be done?


(Alderman) #2

Hi Gavin.

 

Yes it is.  First you need to open your paint layout down to the level of the type format and then either on the default format (or asset specific format if you've specified one) right click and select 'Conditional keywords'. 

 

  • Acquire the locks and under' New Conditions' select Logical Condition from the drop down menu
  • Commit that and you should have a new logical condition labelled condition_1
  • Give that the name you want to test in the layout - e.g. from your example asset_metadata_title_exists
  • In the Logical Keyword 0  field select asset_metadata_  from the dropdown list and commit
  • A new field will appear next to asset_metadata_   In here put the metadata field name e.g. name (whatever you have called it)
  • Commit once more
  • Now right click your Default Format (or asset specific if that's the case) and select Edit Content

Now you can do this:

 

%begin_asset_metadata_title exists%

   display this html code and assets keywords

%else_asset_metadata_title exists%

   display this html code and assets keywords

%end_asset_metadata_title exists%

etc..


(Alderman) #3

Just noticed a typo I made

 

on this line

 

  • Give that the name you want to test in the layout - e.g. from your example asset_metadata_title_exists

I had failed to add the underscore between asset_metadata_title and the word exists


(Gjboyd7) #4

Thats great.

 

Is it possible to do a condition based on

 

 

if (asset_metadata equals 'new format')

   display this code


(Alderman) #5

Yes set up another condition but this time instead of a logical condition select 'Keyword Regexp Condition'.  Commit and fill in a condition name as before, then you'll have to put the metadata field you want to test against in the Keyword field and the value you want to match against in the pattern field.  Then use the %begin_% %else_% %end_% tests as in the other example.


(Bart Banda) #6

Little known fact, is that you can also do is empty conditions without the need of conditional keywords being set up.

 

If you are simply checking if a value is empty or not, you can just do

 

%begin_asset_metadata_name%

%else_asset_metadata_name%

%end_asset_metadata_name%


(Alderman) #7

Thanks for that Bart - perhaps that could find its way into the manuals.  At least we can now go back into our paint layouts and remove a load of conditional keywords :-)


(Nic Hubbard) #8

Little known fact, is that you can also do is empty conditions without the need of conditional keywords being set up.

 

If you are simply checking if a value is empty or not, you can just do

 

%begin_asset_metadata_name%

%else_asset_metadata_name%

%end_asset_metadata_name%

 

You are like the new Avi Miller!


(Avi Miller) #9

 

You are like the new Avi Miller!

 

What does that make me?


(Nic Hubbard) #10

What does that make me?

 

Whoa he returns!


(Avi Miller) #11

 

Whoa he returns!

 

You uttered the Sacred Summoning Words and I appeared.

 

(I'm also amazed that after 5+ years of being away, I'm still the user with the most posts around here. You lot need to lift your game).


(Nic Hubbard) #12

 

You uttered the Sacred Summoning Words and I appeared.

 

(I'm also amazed that after 5+ years of being away, I'm still the user with the most posts around here. You lot need to lift your game).

 

I have tried. I surpassed Greg!


(Avi Miller) #13

 

I have tried. I surpassed Greg!

 

Only 1,600 to go before you surpass me. I'll check back in another 5 years, shall I? :)


(Nic Hubbard) #14

 

Only 1,600 to go before you surpass me. I'll check back in another 5 years, shall I? :)

 

Do it.

 

I think you had a few years on me before I arrived.


(Aleks Bochniak) #15

I suspect google alerts brought Avi Miller back!


(Gjboyd7) #16

Can you only do this on paint layouts?


(Nic Hubbard) #17

Can you only do this on paint layouts?

 

In Matrix 5 you can do this in Standard Pages too.