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

Stumped on using using the return from a function.

 
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
zewtastic
Smarty Rookie


Joined: 26 Dec 2016
Posts: 10

PostPosted: Mon Dec 26, 2016 8:43 pm    Post subject: Stumped on using using the return from a function. Reply with quote

I need to use php function like "mktime", "date", "getdate" and so forth.

So I found I could make a custom function to call.

ex:

Code:

// number of days in a given month.
$smarty->registerPlugin("function","days_in_month", "days_in_month");
function days_in_month($params, $smarty){
    $maxday = date("t",mktime(0,0,0,$params["month"],1,$params["year"]));
    return $maxday;
}


this gives me the number of days in a given month:
Code:

{days_in_month month=$cMonth year=$cYear}


It echoes out the result, but I want to use it in a FOR loop.

How do i use that functions result value in further smarty functions like loops?
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon Dec 26, 2016 9:10 pm    Post subject: Reply with quote

You don't need to register a plugin.
All PHP functions are directly available in a context of Smarty tags' parameters.
Back to top
View user's profile Send private message
zewtastic
Smarty Rookie


Joined: 26 Dec 2016
Posts: 10

PostPosted: Mon Dec 26, 2016 9:20 pm    Post subject: how do I use them? Reply with quote

EDIT: Ok I think I see what you mean, doing some tests.

Thanks
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Tue Dec 27, 2016 12:49 am    Post subject: Reply with quote

I mean something like
Code:
{if isset($var)}something{/if}
is perfectly valid for a template.
Just... don't make it a habit. Keep your messing strictly to display purposes.
Turning your templates into a part of your business logic is a bad business.
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