Regex not working in Design file but working in Paint layout


#1

Hi Guys,

 

            I have this weird situation. I have a regex that is working perfectly in paint layout, but failing in design file ..... Here is the snippet of code I am using in Design file ...

<MySource_AREA id_name="is_city_cairns" design_area="show_if">
<MySource_SET name="condition" value="keyword_regexp"/>
  <MySource_SET name="condition_keyword" value="%asset_url%"/>
 <MySource_SET name="condition_keyword_match" value="^[a-z,0-9,\-,\.,/,:]*cairns[/,\-,a-z]+" />
  <MySource_THEN>The city is Cairns</MySource_THEN>
  <MySource_ELSE>%asset_url%</MySource_ELSE> <!-- Just for Testing URL -->
</MySource_AREA>

The above code always print the ELSE part ...... Why ????

 

My URL is something like this https://www.example.com.au/location/cairns/workshop

 

The regex is 100% correct, I have tested it in multiple online testers such as http://regexpal.com/

 

I have used the same regex in one of the paint layouts, where it works perfectly. Why it's not working in design file ?

 

I'll really appreciate any clues .... BTW, we are on version 4.10

 

Thanks


(Bart Banda) #2

Hi Paul,

Try removing the percentage signs from the value="%asset_url%" part, so just use value="asset_url"

 

Does that help?


#3

Hi Paul,

Try removing the percentage signs from the value="%asset_url%" part, so just use value="asset_url"

 

Does that help?

 

Thanks Bart, Worked perfectly ..... So never use % when comparing "condition_keyword" value in a "show-if" design area ? Right ? or does this rule (no % sign) applies to all design areas ?

 

Bart, another quick question, now I have to make a nested "Show-If" to compare 9-10 different conditions .....  and I am gonna use this approach http://forums.squizsuite.net/index.php?showtopic=11939&p=55628

 

Is this the best and most efficient way to construct nested "show-if" statement or do we have some kind of switch-case thing in matrix ... ?


(Bart Banda) #4

You could maybe use the regex asset for that to make it easier? https://manuals.matrix.squizsuite.net/other-cms-assets/chapters/regular-expression-asset

 

And depending on what you are printing and testing conditions on, it might be easier to do the check inside a standard page and then nest that into the design.