XF 2.2 Template modification with regex within condition

FoxSecrets

Active member
Is it possible to find a element with regex within condition? Or any other approach to get that?

I need something like:
Code:
<xf:if is="condition == 1">
    #(<div [^>]*class="[^"]*first-class[^"]*"[^>]*>)#isU
<xf:else />
    #(<div [^>]*class="[^"]*another-class[^"]*"[^>]*>)#isU
</xf:if>
 
What's the use case exactly? Depending on your exact needs these can maybe just be separate template modifications.
 
It can't be separated, I've already tried.

Basically I need to find a block and modify its child, but it appears 3 times on my page (different parent names but same child name).
So depending on condition, I gotta find a different block to modify its child.
 
I still don't follow I'm afraid. You can tighten or loosen the regex to match as much or as little as you need, including parent or child elements, or you can use multiple template modifications to match different things which may or may not be present.


If you need to apply the replacement conditionally, you can use conditional expressions or <xf:if> in the replacement directly.
 
It's a very specific situation. e.g. If condition 1, it should select 1st parent, if condition 2 select 2nd .....etc
The user will choose (condition) which element he wants. Any idea how to get this?

Code:
<div class="parent-first-class">
    <div class="child-same-class">

<div class="parent-second-class">
    <div class="child-same-class">

<div class="parent-third-class">
    <div class="child-same-class">
 
By the way, I also tried via javascript, but for some reason the element is behind others and even using z-index it doesn't come to front. When I insert one element from template modification it works accordingly, but I need the conditions to check all of them.
 
You can capture the parent class in the regex and then use a conditional expression in your replacement if that's what you mean:


Presumably the actual condition would check against variable or option of some sort?
 
This may (or may not) be clearer to understand: https://regex101.com/r/97FqoX/3

Alternatively you can create separate template modifications for each parent element and then check for the appropriate condition when applying the replacement. It's not clear to me what the nature of your replacement is so, as ever, providing more full and concrete examples may help.
 
Back
Top Bottom