Multiple patterns in conditional


(Tim Trodd) #1

Matrix Version:

Hi,

We have a around 600 courses(pages) but would like to show/hide some stuff on just 5 particular courses.

Normally I would just use metadata in the conditionals e.g. for separating by subject, level etc.

However these are just 5 random courses that need this certain bit hidden/another bit shown and have no patterns between them.

So I just wondered if its possible to use multiple patterns in one conditional? e.g.

Keyword Regexp Condition
matches asset_assetid
pattern: 118500, 125000, 185630 etc.

Or would I need to create a conditional for each one separately? I cant put it in the contents of the page or change the metadata as its all over written straight from our CMM system. So no one actually changes the pages manually in matrix.

Thanks,

Tim


(Bart Banda) #2

So what controls what pages have the conditional information or not? Are you looking to do it via hardcoded asset IDs somehow? Or will it change daily/weekly/randomly?

Can you share a bit more info about how you want to manage this?


(Tim Trodd) #3

We have a course paintlayout that has quite a few conditionals already in place such as

%begin_is_undergraduate%
xxx
%end_is_undergraduate%

where undergraduate is selected in the metadata.

but in this case its just 5 random course pages that need a certain div hidden and something else shown instead.

There is currently nothing that links those 5 courses so normally I would create a new metadata field that you would select on those 5 and it would display if that was ticked etc.

However our course pages get automatically overwritten by our course feed so we don’t change anything on them directly in matrix.

I just wondered if there was a way of hardcoding specific asset ids in a condition as the asset id won’t change and there isn’t going to be any more courses added/removed from it that I can see in the future.


(Bart Banda) #4

Could you then not do something simple like this:

%begin_asset_assetid^replace:1111|2222|3333|4444|5555:^empty:TRUE%
  //Print the unique thing for those 5 courses
%end_asset%

If you are on 5.4 you could use SSJS as well:

<script runat="server">
switch (%asset_assetid%) {
    case '1111':
    case '2222':
    case '3333':
    case '4444':
    case '5555':
        print('Unique thing for those 5 courses');
}
</script>

(Tim Trodd) #5

Hi Bart,

Thanks for this. I have got it working using the first option you sent through so thanks! but it would be really good to get the second version implemented as its using new features from our recent upgrade (5.4.3)

Not sure why but it doesn’t seem to be working, I am using this:

<script runat="server">
switch (%asset_assetid%) {
    case '187834':
    case '154668':
        print('<p>Statement is true</p>');
}

where the asset id of the page I am viewing is 187834. Nothing appears. I tested to make sure the ssjs is working using

<script runat="server">
  print('<h1>%asset_name%</h1>');
</script>

and this comes through as expected. So not sure why the case isn’t working?


(Bart Banda) #6

Ah, maybe because we’re comparing a number with a string. Try:

<script runat="server">
switch ('%asset_assetid%') {
    case '187834':
    case '154668':
        print('<p>Statement is true</p>');
}
</script>

(Tim Trodd) #7

ahhh of course! thanks! it works