Replace_keywords problem


(Phil Mcphee) #1

I'm working on an implementation for a social media gallery where users can upvote/like content. I'm storing the info about what content they've liked as a list of asset ids in a metadata field for the user asset.

 

In the asset listing for the gallery, I'd like to output (for the moment) just a simple "yes" or "no" string for each image if its asset number is listed in the user metadata field for images they've liked. This is my keyword:

 

%globals_user_metadata_gallery_likes^replace_keywords:contains:{asset_assetid}:yes:no%

 

The problem I'm having is that my {asset_assetid} keyword is being treated globally, rather than in the context of the asset listing. It's checking to see if the gallery_likes metadata contains the asset id of the current page (the gallery) rather than the current asset being listed (the image).

 

Is there a way round this? I can always javascript my way out of it, but I'd love to do this server-side. Is there a global variable I can use to get the currently listed asset ID?


(Aleks Bochniak) #2

There's a session variable you can use

https://manuals.matrix.squizsuite.net/asset-listing/chapters/list-current-asset-id

 

What advantage is there with storing the assetids of pages liked by a user on the user's assetid, rather than the other way round?


(Bart Banda) #3

I think this is due to you being in the global context of the keyword when doing the replace_keyword modifier with asset_assetid. That modifier by default uses the context of the asset you are applying the keyword to, which actually should give you a check against the user's asset id, not the current page's. I reckon we'd need another keyword for this where you can print something like:

 

%globals_user_metadata_gallery_likes^replace_keywords:contains:{this_asset_assetid}:yes:no%


(Phil Mcphee) #4

Awesome. Aleks, thanks so much for the different approach, that solves my problem perfectly - I'll just do it the other way round:)

 

Bart, good to know that at least I wasn't going crazy in not getting my approach to work!


(Kequi) #5

Hi Bart,
Are there any plans to implement this?
I can see a lot of where it would be useful - particularly comparing a current page to a listed or nested page.
Also - can I suggest you add a short line to the manuals explaining that you can’t mix global and non-global contexts when using the ^replace_keywords modifier.
Thanks
Karl


(Bart Banda) #6

Not at this stage, hasn’t been raised in our roadmap yet however in 5.4 this will be a lot easier using server side JS snippets you can create to make this filtering a lot more flexible and powerful.