|
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 |
bimal Smarty Elite
Joined: 19 Apr 2007 Posts: 423
|
Posted: Tue Nov 23, 2010 11:49 am Post subject: How to avoid using {php}...{/php} tags |
|
|
In some old applications that were built on Smarty, we can see some codes like:
Code: | {php}echo date('l, jS F Y'){/php} |
Smarty 2.x.x did support this well. But this is how, you can upgrade your same script for new releases of smarty:
The {php}...{/php} tags are no more enabled by default.
The second one produces the exactly same result and works in older versions of Smarty too. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Nov 23, 2010 2:38 pm Post subject: |
|
|
FYI, date_format also supports the date() modifiers as of Smarty 3.
{$smarty.now|date_format:"%Y-%m-%d"} <-- strftime()
{$smarty.now|date_format:"l, jS F Y"} <-- date()
Both modifier formats are accepted.
To throw in another option, Smarty 3 also accepts PHP functions directly:
{date('l, jS F Y')}
However, the plugin approach is recommended. |
|
Back to top |
|
bimal Smarty Elite
Joined: 19 Apr 2007 Posts: 423
|
Posted: Tue Nov 23, 2010 6:42 pm Post subject: short and beautiful |
|
|
Quote: | {date('l, jS F Y')} |
Looks, this is a native PHP replacement; short and beautiful.
{'l, jS F Y'|date} is even shorter and less confusing due to single pairs of braces only.
But these both produce a common compiled output.
Is it due to `date` being a native php callable function?
I would definitely go with it. |
|
Back to top |
|
TakingSides Smarty Rookie
Joined: 11 Dec 2010 Posts: 30
|
Posted: Fri Jan 28, 2011 9:04 am Post subject: |
|
|
Also, the date_format modifier supports both string dates, and timestamps. So long as the string date is recognised by the strtotime() |
|
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
|