Please wait for 15 seconds...

Thursday, 9 January 2014

Smarty has many in built functions/modifiers that we can trigger them by just using a keyword. Most of these functions/modifiers are used many time while coding. Today I am presenting you a list of these type of build in functions/modifiers with their uses.

But we need to understand first how to use these keywords efficiently. It is easy, just observe below codes:

We can also use two or more keywords at a time.

Now lets take a look at these keywords.
{$string|base64_encode} : Encode text string into base64 encoded string.

{$string|base64_decode} : Decode base64 encoded string into normal text string.

{$string|serialize} :  Serialize the string

{$string|unserialize} :  Unserialize the string

{$string|upper} : Convert string into upper case

{$string|lower} : Convert string into lower case

{$string|ucfirst} : Convert first character into upper case of the string

{$string|lcfirst} : Convert first character into lower case of the string

{$string|capitalize} : Capitalize first character of all words in the string. more info

{$string|count_words} : Count number of words in the string

{$string|count_characters} : Count number of characters in the string

{$string|count_characters:true} : Count number of characters in the string including blank spaces

{$string|count_paragraphs} : Count number of paragraphs in the string. more info

{$string|count_sentences} : Count number of sentences in the string. more info

{$domain_bids|count} : Count number of elements in an array

{$string|cat:$append_substring} : Append a sub string. more info

{$string|default:$default_value} : If variable does not have any value already then smarty assign given string as default string. more info

{$string|truncate:$append_at:$append_me} : Appends sub string at the end of the string. more info

{$string|strip_tags} : Strip all HTML tags. more info

{$string|strip} : Strips all repeated blank spacesin the string. more info

{$string|replace:$find_me:$replace_me} : Just like PHP str_replace()

{$string|regex_replace:$regex_expression:$replace_me} : Replace sub string against regex expression.

{$string|nl2br} : Replace \n into <br />

{$min|rand:$max} : Generate a random number between minimum and maximum given number 

And there are many other variable modifiers in smarty like:
escape:'htmlall' : Convert normal text into HTML entities encode string.

unescape:'htmlall' : Converts HTML entities encode into normal text

date_format : Format date based on given parameters

to_charset : Transcode a string from the internal charset to a given charset.

Posted by Atul Prasad Gupta


Post a Comment

Subscribe Techsirius

Techsirius on Facebook