|
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 |
zewtastic Smarty Rookie
Joined: 26 Dec 2016 Posts: 10
|
Posted: Mon Dec 26, 2016 8:43 pm Post subject: Stumped on using using the return from a function. |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Mon Dec 26, 2016 9:10 pm Post subject: |
|
|
You don't need to register a plugin.
All PHP functions are directly available in a context of Smarty tags' parameters. |
|
Back to top |
|
zewtastic Smarty Rookie
Joined: 26 Dec 2016 Posts: 10
|
Posted: Mon Dec 26, 2016 9:20 pm Post subject: how do I use them? |
|
|
EDIT: Ok I think I see what you mean, doing some tests.
Thanks |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Dec 27, 2016 12:49 am Post subject: |
|
|
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 |
|
|
|
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
|