Variable Modifiers :
Variable modifiers can be applied to variables, custom functions or strings. To apply a modifier, specify the value followed by the | (pipe) and the modifier name. A modifier may accept additional parameters that affect its behavior. These parameters follow the modifer name and are separated by : (colon).
Example:
{$smarty.now|date_format:"%Y/%m/%d"}
Demo:
Some of the variable modifiers are given below.
capitalize
This is used to capitalize the first letter of all words in a variable.
Example:
{$name}
{$name|capitalize}
Demo:
count_characters
This is used to count the number of characters in a variable.
Example:
{$name}
{$name|count_characters}
{$name|count_characters:true}
Demo:
cat
This is used to concatenate a value to the given variable.
Example:
{$name|cat:" is travelling around the world."}
Demo:
date_format
This is used to show the date & time.
Example:
{$smarty.now|date_format} <br/>
{$smarty.now|date_format:"%A, %B %e, %Y"}<br/>
{$smarty.now|date_format:"%H:%M:%S"}<br/>
{$yesterday|date_format}<br/>
{$yesterday|date_format:"%A, %B %e, %Y"}<br/>
{$yesterday|date_format:"%d-%m-%Y"}<br/>
{$yesterday|date_format:"%H:%M:%S"}
Demo:
lower
This is used to lowercase a variable.
Example:
{$country}
{$country|lower}
Demo:
upper
This is used to uppercase a variable.
Example:
{$country}
{$country|upper}
Demo:
explode
Returns an array of strings, each of which is a substring of string formed by splitting it on boundaries formed by the string delimiter.In the below example delimiter is comma ','.
Example:
{$string_with_commas="Rama,Gopal,Saswat,Debasis"}
{assign var=images value=","|explode:$string_with_commas}
{foreach from=$images item=expld_val name=expld_name}
{$expld_val}<br/>
{/foreach}
Demo:
string_format
This is a way to format strings, such as decimal numbers and such.
Example:
The number is 45.3964879
{$number|string_format:"%.2f"}
{$number|string_format:"%d"}
Demo:
truncate
This truncates a variable to a character length, default is 80.As an optional second parameter, you can specify a string of text to display at the end if the variable was truncated.
Example:
{$description}
{$description|truncate}
{$description|truncate:30}
{$description|truncate:30:""}
{$description|truncate:30:"---"}
{$description|truncate:30:"":true}
{$description|truncate:30:"...":true}
Demo:
-
I have an array $smarty->assign('a', array(1=>array('subha','amar'),4=>array('nibedita','harapriya')));
Write the smarty code to capitalize the first letter of each element of the array and should show two elements in a row.
-
Write the code to display the date of the day which will come after 5 days from today's date.
-
I have an array $smarty->assign('a', array(1=>array('Subha','aMar','biShnu'),4=>array('nibEdita','haRapriya','pReeti')));
Write the smarty code to write each element of the array in lower and upper case separately and should show three elements in a row.
-
Make a text field for inputing number and and a button . When the button will be pressed then if the number is a integer then show the next number to it and if the number is
a floating point number then display the number rounded up after the three digits after the decimal point.
-
Make a text box for inserting the address and a button when I will press the button then the address should show me up to 10 characters the "...." will appear.
- Make registration form having fields for inputing name,city,state,country,date of birth,gender,hobbies,and an image .
Here date of birth should be in dd/mm/yyyy format and city,state and country should be drop down,and hobbies should be check box.
Insert the value to the data base
List the data as follows
Put the address up to 30 characters
After that put a option for edit and then edit in the corresponding data base and give the option to delete it.