|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
JurgenD Smarty Rookie
Joined: 20 Jul 2005 Posts: 12 Location: Belgium
|
Posted: Wed Jul 20, 2005 5:16 pm Post subject: Request variable modifier: regex (for compare with if) |
|
|
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 |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Jul 20, 2005 5:29 pm Post subject: |
|
|
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 |
|
|
|
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
|