Show If Design Area based on metadata value


(Tim Davison) #1

Is it possible to use a show_if design area with the decision based on existence of a metadata value (or even a specific value).  

 

I'm trying to control how the page title is printed out.

  • We have a design area that uses a reverse lineage to show a 'default' page title based on that asset's location in the tree.
  • I have a metadata field that, if filled, I want to override this default page title.  But if empty, use the default reverse lineage defined above.

However, does not seem to work.  Similar post is this one: http://forums.squizsuite.net/index.php?showtopic=5035

 

My code thus far: |

<MySource_AREA id_name="page_title" design_area="show_if" print="no">
  <MySource_SET name="condition" value="keyword_regexp" />
  <MySource_SET name="condition_keyword" value="asset_metadata_LayoutOptions.PageTitle^charcount" />
  <MySource_SET name="condition_keyword_match" value="[0]" />
  <MySource_THEN><MySource_PRINT id_name="page_title_default" /></MySource_THEN>
  <MySource_ELSE>%asset_metadata_LayoutOptions.PageTitle%</MySource_ELSE>
</MySource_Area>
...
...
...
...
<title><MySource_PRINT id_name="page_title" /></title>

The condition always comes out as FALSE.

 

I've also tried a number of other variations, e.g. matching on '0' not '[0]', change the condition_keyword value to just the metadata value, and changing the regex to any number of combinations, from matching on a non-empty string, matching on the exact value 'default', etc.  Seems I've tried everything.  

 

Post I've linked to above seems to indicate that asset metadata is being evaluated at a different time/place, but I know I've used Show_If's before based on metadata values.  

 

What am I doing wrong?  Or does anyone have an alternative way to do it?  (besides customisations and/or paint layouts - I know these could be used but would have flow-on effects to site design complexity).

 

Matrix v5.1.1


(Bart Banda) #2

Hmmm, I would have thought metadata keywords would work here.

 

Does the keyword value need to include the percentages to make up the keyword perhaps?

<MySource_SET name="condition_keyword" value="%asset_metadata_LayoutOptions.PageTitle^charcount%" />

Another thing to try could maybe be to wrap the lineage area in keyword condition tags:

%begin_asset_metadata_LayoutOptions.PageTitle%
  %asset_metadata_LayoutOptions.PageTitle%
%else_asset_metadata_LayoutOptions.PageTitle%
  <MySource_PRINT id_name="page_title_default" />
%end_asset_metadata_LayoutOptions.PageTitle%

Not sure if begin/else works in parse files but if not, you could try and just comment that lineage area out with the conditional keywords, not as clean/pretty though:


(Evan Wills) #3

The keyword doesn't need the percentage.

 

When I do this, I usually use a select metadata field which has key/value pairs. If you are doing the same, then you might need to match the fields value, rather that its key.

 

e.g. If my metadata field's options are:

  • [0] Show lineage title
  • [1] Show page title

Then my "condition_keyword_match" would be "Show lineage title", not "[0]" or "0".

 

Also if it's a literal match, then you don't need the regex character class ("[0]"), the literal "0" character will do.


(Tim Davison) #4

Thanks all for comments.  Tried everything suggested above, still to no avail.

 

I've used metadata select fields successfully this way before, but in this case it's just a text field and it's not working.  I'm really not sure why.

 

Bart, I like your idea with the %begin and %end keywords (and use that a fair bit elsewhere).  It will work in this case but it won't in another of my cases, specifically the breadcrumbs.  If I use the approach you've suggested I won't be able to turn off the breadcrumbs in a customisation if I need to down the road.

 

Really frustrating, I don't want to have to create a design customisation just so I can modify the page title, as that means I will have to re-create all the permutations of our children customisations (not to mention the oeverhead that we will need to apply customisations case-by-case, would prefer authors to do it themselves via metadata).


(Tim Davison) #5

Update: Tried using one of the suggestions from Bart, specifically:

%begin_asset_metadata_LayoutOptions.PageTitle%
  %asset_metadata_LayoutOptions.PageTitle%
%else_asset_metadata_LayoutOptions.PageTitle%
  <MySource_PRINT id_name="page_title_default" />
%end_asset_metadata_LayoutOptions.PageTitle%

but it's still printing out the 'else' logic. Have triple-checked the field names and values in the metadata schema.  Seems like the parse file is just not able to access the metadata values no matter what I do.  Above code works fine in a Std Page embedded by a nested content in the design, but not directly in the parse file itself.


(Evan Wills) #6

Bart, I've never seen the code you're talking about. Is there somewhere I can look at documentation for it. It looks interesting.

 

 

Within the show_if statemetn, I'm pretty sure that you shouldn't be using the '%' characters in the

<MySource_SET name="condition_keyword" value="%asset_metadata_LayoutOptions.PageTitle^charcount%" />

statement.

It should read:

<MySource_SET name="condition_keyword" value="asset_metadata_LayoutOptions.PageTitle^charcount" />

(Bart Banda) #7

You can read about conditions here:

http://manuals.matrix.squizsuite.net/paint-layouts/chapters/conditional-keywords-screen

http://manuals.matrix.squizsuite.net/asset-screens/chapters/conditions 

 

But it basically allows you do conditionally print content within those keyword structures based on if a keyword is empty or not. 

 

 

Tim, I copy-pasted your code into a 5.1.12.0 system and it works as expected. I can't remember any bugs that would have caused this that were fixed, but maybe worth doing an upgrade. 


(Tim Davison) #8

Thanks for checking that Bart.

 

There's another issue I've found - not sure whether I should raise it as new topic or keep it in this one.  I'm using the conditional logic code similar to what you've supplied above:

%begin_globals_asset_metadata_LayoutOptions.BannerText%
<div class="banner">
  <div class="banner-content">
    <p>
      <img class="arc" src="%globals_asset_metadata_LayoutOptions.BannerIcon%" alt=""/>
      %globals_asset_metadata_LayoutOptions.BannerText%
    </p>
  </div>
  <img class="banner-image print-hidden" src="%globals_asset_metadata_LayoutOptions.BannerImage%" alt="" />
</div><!-- /.banner -->
%end_globals_asset_metadata_LayoutOptions.BannerText%

So logic I'm expecting is the code in between the begin and end directives prints only if the metadata field LayoutOptions.BannerText has been filled.  This is nested into the site design as a nested content area, this code is on a Std Page asset (hence the 'gobals_' to get to the asset itself).

 

Works perfectly *except* if I put this nested content into Safe Edit.  When I do that, logged in users still see if correctly, but for Live view it's no longer doing the conditional - it prints out the inner contents - basically a heap of empty html.  Once I put it back to Live again it starts working fine again. 

 

Possibly also just a nuance of my version (v5.1.1)


(Bart Banda) #9

Hi Tim,

I tested this and can confirm this is a bug in the latest version of Matrix as well. I've submitted a bug report and will hopefully be fixed in the next release. 

https://squizmap.squiz.net/matrix/7323 


(Tim Davison) #10

Cheers, thanks mate.