XF 2.1 strpos in templates

grantus

Active member
Licensed customer
I've been searching but I don't see anything about strpos. What would be the equivalent in a template?

Basically, I want to do this:
Code:
<xf:if is="strpos({$xf.uri}, 'forums') !== false">
    forums
<xf:else />
    {$xf.uri}
</xf:if>

because I just need to see if the URL contains certain words so I can do an if/else.
 
You can use the contains function (contains($xf.uri, 'forums')), though note it is case-insensitive.
 
You can use the contains function (contains($xf.uri, 'forums')), though note it is case-insensitive.
That's interesting, I've never seen that function before. This works great. Where is it normally used?
 
I don't think it's used anywhere in the core. You can view a full list of template functions and filters in src/XF/Template/Templater.php.
 
Back
Top Bottom