Logical metadata-dependant Conditional Keyword Statements in a Container Template not evaluating correctly


(Emily) #1

Matrix Version: 5.3.1

Hi all, I am having a problem with my Conditional Keyword Statements not evaluating correctly when I am using them through a paint layout applied attached to a Container Template applied to a container.

So the metadata fields live on the page asset that has the container to which the template is applied.
I have it reading the metadata content perfectly fine in the Container Template using the %globals_asset_metatata_% – i.e. if I tell it to print the contents of the field, it will.

However, when I then create a Conditional Keyword so that I can only display if the metadata field has contents, it always returns as though the field has contents – even when it does not.
I have tried using both the Logical and Regex condition types. Neither evaluate as false when there is no field input. (Yes, still using the Globals metadata keyword)

I have used Conditional Keywords on paint layouts applied directly to the page before, without a problem. I am not sure what is going on here and why it doesn’t work.

Anyone else had this problem?
Any ideas of what I may be doing wrong? or how to fix?

Thanks,
Emily.


(Bart Banda) #2

Hey Nen,
So if I udnerstand correctly, you want to access the metadata field value on the Standard page within the PL that is used on the content container via the template?

Have you tried doing something like this into the type format of the PL?

%begin_globals_asset_metatata_<value>%
  value of standard page metadata field is NOT empty
%else_globals%
  value of standard page metadata field IS empty
%end_globals%

(Emily) #3

Hi Bart,

Is that different to the standard conditional keywords?
I notice the begin tag is different from the else and end tags… I’m not familiar with this…

Is the %begin_global% a conditional keyword that you have then modified with asset_metadata_field? Or is there a set matrix keyword replacement of %begin_global_asset_metadata_field%?

At the moment my page just has a logical condition keyword, in the standard “%begin_ConditionName%”, else and end formats.

I’ll test this out when I’m back in the office on the computer, and see if it does the trick.

Thanks,
Emily.


(Bart Banda) #4

Have a look at https://matrix.squiz.net/manuals/keyword-replacements/chapters/conditional-keywords
That should explain it.
Basically an alternative way of writing conditional keyword blocks without even having to use the conditional keywords screen on a paint layout, a lot easier to use.


(Emily) #5

Thanks Bart. Interesting addition (hard to keep up with all the new additions in each major/minor upgrade!)

It works if I put it into the actual page contents, but for some reason doesn’t work when I put it in the paint layout (attached via a Container Template) – literally cut and paste it.

Not sure if that is just my system being ‘special’ (it is a self-hosted non-Squiz-installed version of Matrix), or if there is a bug…? My bets are on my system being ‘special’ since it doesn’t seem anyone else has come across this problem.

However, I think that the only reason I needed to use the PL was for the conditional keywords for metadata, so I think using these Keywords in the PC should be a fine solution. :slight_smile:


(Emily) #6

I realised that I DO need to use a paint layout, because we are wanting to template it across multiple pages, and don’t want to have to edit each one each time something in the layout template needs to change…

So, I have done some more testing & investigating and it seems that it ONLY occurs for the LAST %begin_globals_metadata_value% statement in the list. It doesn’t matter which one is the last one in the list, it is always the last one that fails. If I remove the last one, then the new-last-one will fail (when it previously worked).

I have 6 metadata fields:

  • service-1-implemented
  • service-2-implemented
  • service-3-implemented
  • service-4-implemented
  • service-5-implemented
  • service-6-implemented

This is my code:

						

If I add a 7th metadata field, and add it to the end, then the 6th keyword condition WILL work. But if the 7th is blank, the 7th will then fail.

If I remove the service-6-implemented section, then the 5th one will fail if it blank. But if there is a 6th or 7th, then the 5th will not fail even if it is blank.

o.O

I am stumped.


(Bart Banda) #7

Interesting. Just to be clear, you are wanting to print the metadata values from the standard page asset, within the paint layout applied to the content container?

So:

  • Standard Page <- Has the service-X-implemented metadata values?
    • Content Container <- Has template with Paint Layout applied

And you can correctly reference those metadata values in the PL on the Template by just using
%globals_asset_metadata_service-2-implemented% ?

Another method you could try is this:

%globals_asset_metadata_service-2-implemented^as_asset:asset_name_linked^tagif:li%

Does that work?


(Emily) #8

Correct, I was originally trying to put it in a PL which was attached to a Content Container via a Content Template.

However, I am also testing / trying it with:

  • PL applied directly to page via PL screen
  • PL applied to asset contents via %asset_contents_paint_assetID%

Neither of the 3 approaches work.
Yet it works perfectly (with identical code) if I put the code straight into a Content Container of the end page. (But linking this container into every page isn’t ideal, because Simple Edit users won’t be able to create new pages).


As for the tagif modifier — that seems to work. So for this instance that will be a good workaround.

However, I do know there are other instances where the content to show isn’t an asset attribute/metadata/etc that can be called from a keyword… So will have to see if I can find an alternative or fix for those situations. (I could make the text in a metadata field, but it would still need to depend on a different metadata field to decide whether the block of text should show or not; i.e. “if there is a video in video-field then show text-field at this place further down the page. Else, if no video, show this static image instead”.)

However, it is good to know there is not some obvious thing I am forgetting / overlooking that is causing this weird behaviour…

The odd thing is, when I apply a paint layout to an asset listing Type Format, it worked perfectly fine. o.O
(That was using the ‘old’ style Conditional Keyword, as I was wanting it to check if ANY of 5 fields were ‘true’.)


Accessing the `Content Container Template` & `Content Container` via keywords
(Bart Banda) #9

Yea the concept of the globals keywords in context with the content templates can be tricky. Especially if you are nesting in assets into the template PL that is applied to the container.

I think the best way to debug/advise further would be to have a look closer on the actual implementation of what you are trying to do to see if there are some gotchas that way.

Good to hear you can workaround this instance for now though.