Apologies if this has been asked before - couldn't find it. The design I am trying to implement wraps a span around instances of the search string in the search results. I couldn't see a way of doing this out of the box, and my first stab at keyword modifiers doesn't seem to do it:
Can anyone sort out my modifiers, or give another way of doing this?
Edit: just realized that of course I would not want to modify %asset_name_linked% as it would destroy the link HTML, so ignore my choice of base keyword replacement - it's the modifiers that I need to get right.
Are you opposed to using javascript? It would be super simple doing it that way. Sometimes those long keyword modifier solutions seem like too much work.
You'd still need a replace keyword to get the class into the tag though, I imagine. (maybe something like replace^<span:<span class="searchTerm"% will do)
For something as simple as this, yes. Why on earth would I want to deny a proportion of my users a feature which the client-server model does not dictate can only happen client-side?
maybe the tag or tagif modifiers
I've used those extensively before. Problem is that the design requires the surrounding tag to have a class. I don't suppose tagif supports them, does it? Something like:
I've used those extensively before. Problem is that the design requires the surrounding tag to have a class. I don't suppose tagif supports them, does it? Something like:
%asset_name_linked^tagif:span.searchTerm%
Can you get away with highlighting it without using a class? Can't you just wrap it in a <strong> tag or target it via parent CSS selector?
I've used those extensively before. Problem is that the design requires the surrounding tag to have a class. I don't suppose tagif supports them, does it? Something like:
Hi Tom,
I've just tested the example I gave in my last reply and it works for me.
Can't you just wrap it in a <strong> tag or target it via parent CSS selector?
I don't know that that would be quite semantically correct, though perhaps the q tag (if it's not deprecated) would be appropriate. Thanks. I still don't really understand why that might work when my version does not, though.
Well, I just can't get replace_keywords to work at all in this context, which rings a bell - did I post elsewhere about it not working in another context? I'm on 4.14.3.
I haven't seen 'globals_get_queries_term_query' is that just for a GET parameter called 'queries_term_query'?
This is in 4.18.3 however, and I think early versions of the 'replace_keywords' modifier did not support globals keywords in the replacements... I'm not sure what version that changed in, but I would try your modifier using a meta field or short_name attribute for the search term, just to confirm whether it's a problem with the globals keywords inside a replace_keywords modifier.
No, yours doesn't work for me, and I've confirmed that if I try to highlight a non-global keyword, it works. Yes, that is my search query GET variable, using the replacement specified for search results bodycopies:
%<field_name>_query_terms%
I've copied the search field code from an existing site on our Matrix install. Is the rather unwieldy search field name hard-coded, or can I set it somewhere. I have concerns that there is a naming conflict between the keyword and the modifier.
We're on 4.14.3. Can anyone confirm that modifiers don't work on global keywords in this version?