Compare current URL to its sibling using Keyword Replacement Values


(Lewis) #1

Hi,

I’ve constructed this %asset_sibling_prev^as_asset:asset_url_path^contains:{asset_url_path^explode:/^index:2}:1:0% but it only returns false (0) even when:

the previous sibling is /foo/bar/baz
the current adjacent asset is /foo/bar/bla

I’ve also tried %asset_sibling_prev^as_asset:asset_url_path^explode:/^in_array:{asset_url_path^explode:/^index:2}:1:0%

Any ideas?


(John gill) #2

tl;dr Seems that ^explode:/ doesn’t work inside the replace keywords {}. Probably an escaping issue of some kind.

You can check this by replacing the outer keyword with something that will reveal what the inner section is being evaluated to.

%asset_status_code^append:{asset_url_path^explode:\/^index:2}% 
= 2{asset_url_path^explode:\/^index:2}

which indicates that the {} is failing to be evaluated, probably due to the /. A simpler inner keyword works fine even with a modifier.

%asset_status_code^append:{asset_url_path^append:q}%
= 2/forum-sibling-keyword/subfolder/page2q

So modifiers work, but you can’t explode by /. You could source essentially the same information a different way with asset_linking_lineage

%asset_url_path^explode:/% 
= ["","forum-sibling-keyword","subfolder","page2"]

%asset_linking_lineage^as_asset:asset_web_path% 
= [null,"forum-sibling-keyword","subfolder","page2"]

using this alternative source seems to work inside the replacement {}

%asset_sibling_prev^as_asset:asset_url_path^contains:{asset_linking_lineage^as_asset:asset_web_path^index:2}:1:0%
= 1

That being said, won’t it always evaluate to true for sibling assets?


(Lewis) #3

Hi JohnGill,

Thanks for your reply.

I kept going and I’ve come up with this %asset_sibling_prev_type_1^eq::1:0% in SSJS as I think you’re right, what I was doing before was always evaluating to true.

The above is used to determine whether the asset listing has changed group, for example:

  • Foo
    • Shadow asset
    • Page 1
    • Page 2
  • Bar
    • Shadow asset
    • Page 3
    • Page 4

I found that the code I was using previously was returning the shadow asset, which happens to always be Type 2 by default. The above code checks that the %asset_sibling_prev% is looking at a Type 2 asset. If it is, I can imply that Page 3 (for example) is at the top of that group (Bar) and so I can print Bar on the screen and open a list list item tag to enclose the next two pages and so on.

I tried using grouping in the asset listing which worked perfectly but always listed the groups in an odd order, despite different attempts to get it to list in the order assets appear in the asset map.

The approach I’m using now works, just gotta figure out how to wrap the HTML and open/close the tags right so they appear correctly to the user.