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

Including function in {if} statement

 
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 -> General
View previous topic :: View next topic  
Author Message
spunkymungbeans
Smarty Regular


Joined: 14 Mar 2005
Posts: 49

PostPosted: Sat Aug 19, 2006 3:05 pm    Post subject: Including function in {if} statement Reply with quote

I have the following which is causing me grief:

Code:
            
<?php
if (CountModules('m1') >= 1 OR CountModules('m3') >= 1 ) { 
etc
}
?>


I have created a plugin to return the CountModules value, eg:

{CountModules position='m1'}

But how do I include the results in an if statement?
_________________
Leonie
Back to top
View user's profile Send private message
boots
Administrator


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

PostPosted: Sat Aug 19, 2006 9:47 pm    Post subject: Reply with quote

Create a modifier rather than a function plugin.
Back to top
View user's profile Send private message
spunkymungbeans
Smarty Regular


Joined: 14 Mar 2005
Posts: 49

PostPosted: Sun Aug 20, 2006 2:50 am    Post subject: Reply with quote

Thanks. I've done this:

Code:

function smarty_modifier_mosCountModules ($position) {
   return mosCountModules($position);
}


called thus:

Code:

{if ("m1"|mosCountModules gte 1) OR ("m3"|mosCountModules gte 1 ) }
etc...

_________________
Leonie
Back to top
View user's profile Send private message
boots
Administrator


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

PostPosted: Sun Aug 20, 2006 11:09 pm    Post subject: Reply with quote

It seems that mosCountModules is already defined as a normal PHP function. As long as you don't use Smarty's security features, it should be available automatically both as a modifier (without writing a plugin wrapper) and as a valid function that can be used in if statements.
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 -> General 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