Wednesday, August 25, 2010

Mount The Sims 3 On Mac

Small tips & tricks with Smarty

preparing the new website (coming soon completely online, we look forward:)) I used some of these methods with Smarty that are not complicated but very useful, and may be useful.

1. Show age, that is updated dynamically
In this example we will always show my real age (1985 is my date of birth) using a mathematical equation and using $ smarty.now to retrieve the current year:

 
{math equation = "x - 1985" x = $ smarty. now

3. Modifier 'default' for empty variables
To see an empty variable instead of several lines of code and the use of a
as if in this case:


 


{if $ item eq''}
default item value
{else} {$ item

} {/ if}

 
you can use the default modifier this: could be the case of lists or tables or other items, in which you want to alternate two different colors of background:





{$ item CSS

{foreach from = $ name = projects workslist item =

project} {if $ smarty. foreach.workslist.iteration is not odd} {else}
 
{/ if} { / foreach}
Even more elegant solution might be a function
cycle.

5. Separated list of character
For example, if we want to print a list of names separated by a comma, but (obviously) avoid the final comma:

 {section name = loop = $ sectionname 
names} {$ names [sectionname]} {if $ smarty.section.sectionname.last == false} {/ if}
{/ section}

The output would be something like:

Warty, Feisty, Karmic, Breezy, Lucid




0 comments:

Post a Comment