Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Request variable modifier: regex (for compare with if)

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
JurgenD
Smarty Rookie


Joined: 20 Jul 2005
Posts: 12
Location: Belgium

PostPosted: Wed Jul 20, 2005 5:16 pm    Post subject: Request variable modifier: regex (for compare with if) Reply with quote

I wrote a header.tpl and for the admin section it should include some javascript, but not for the regular sections of the site.

There seems to be no way to take a part from a string, in this case a part of the URL. So i did it this way:

{if $SCRIPT_NAME|truncate:6:"" eq "/admin"}
{/if}

It would be nice to have a regex grep func. which can be use in
the if section. like this $var|grep('regex')
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Jul 20, 2005 5:29 pm    Post subject: Reply with quote

You can use PHP functions as modifiers, so preg_match is available; however, this will reverse the normal order that you might expect:

{if $regex|preg_match:$search}

http://smarty.php.net/manual/en/language.modifiers.php

You can use PHP functions in if statements directly as functions.

{if preg_match($regex, $search)}

On the other hand, IMO doing a regex in-template is bad form -- it is often better to wrap it in a custom plugin modifier and hide the regex details from the template user.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP