array_diffComputes the difference of arrays. array_diff($array1, $array2) Type: Function Example: {$array1 = ['green', 'red', 'blue']} { "2": "blue" } |
array_flipExchanges all keys with their associated values in an array. array_flip($array) Type: Function Example: {$fruits = ['d'=>'lemon','a'=>'orange','b'=>'banana','c'=>'apple']} { "lemon": "d", "orange": "a", "banana": "b", "apple": "c" } |
array_intersectComputes the intersection of arrays. array_intersect($array1, $array2) Type: Function Example: {$array1 = ["green", "red", "blue"]} [ "green", "red" ] |
array_keysReturn all the keys or a subset of the keys of an array. array_keys($array) Type: Function Example: {$fruits = ["d"=>"lemon","a"=>"orange","b"=>"banana","c"=>"apple"]} { "d", "a", "b", "c" } |
array_popPop the element off the end of array. array_pop($array) Type: Function Example: {$colors = ['red','blue','green','purple']} [ "red", "blue", "green" ] purple |
array_pushInserts one or more elements to the end of an array. array_push($array,"value1","value2") Type: Function Example: {$colors = ['red','blue','green','purple']} {$tmp = array_push($colors,"orange","yellow")} <pre>{json_encode($colors, 128)}</pre> [ "red", "blue", "green", "purple", "orange", "yellow" ] |
array_reverseReturn an array with elements in reverse order. array_reverse($array) Type: Function Example: {$fruits = ["d"=>"lemon","a"=>"orange","b"=>"banana","c"=>"apple"]} {$fruits_reversed = array_reverse($fruits)} {$utils->jsonPrettyPrint($fruits_reversed)} { "c": "apple", "b": "banana", "a": "orange", "d": "lemon" } |
array_searchSearches the array for a given value and returns the first corresponding key if successful. array_search('needle', $array) Type: Function Example: {$colors = ['red','blue','green','purple']} [ "red", "blue", "green", "purple" ] 1 |
array_shiftShift an element off the beginning of array. array_shift($array) Type: Function Example: {$colors = ['red','blue','green','purple']} [ "blue", "green", "purple" ] red |
array_spliceRemove a portion of the array and replace it with something else. array_splice($array, offset) Type: Function Example: {$colors = ['red','blue','green']} [ "blue", "green" ] red |
array_sliceReturns selected parts of an array. array_slice($array,start,length,preserve) Type: Function Example: {$colors = ['red','blue','green','purple']} [ "blue", "green" ] |
array_unshiftPrepend one or more elements to the beginning of an array. array_unshift($array) Type: Function Example: {$colors = ['red','blue','green','purple']} [ "yellow", "red", "blue", "green", "purple" ] |
array_uniqueRemoves duplicate values from an array. array_unique($array) Type: Function Example: {$colors = ["d"=>"green","a"=>"green","b"=>"yellow","c"=>"blue"]} { "d": "green", "b": "yellow", "c": "blue" } |
array_valuesReturn all the values of an array. array_values($array) Type: Function Example: {$fruits = ["d"=>"lemon","a"=>"orange","b"=>"banana","c"=>"apple"]} { "lemon", "orange", "banana", "apple" } |
asortSort an array and maintain index association. asort($array) Type: Function Example: {$colors = ['red','blue','green','purple']} { "blue", "green", "purple", "red" } |
arsortSort an array in reverse order and maintain index association. arsort($array) Type: Function Example: {$colors = ['red','blue','green','purple']} { "red", "purple", "green", "blue" } |
base64_encodeEncodes data with MIME base64. Type: Modifier Example: {"foo"|base64_encode} Zm9v
|
countCounts the number of items in an array. count($variable) Type: Function or Modifier Example: {$colors = ['red','blue','green','purple']} Function Syntax:
The colors array contains 4 items. Modifier Syntax: The colors array contains 4 items. |
count_charactersCounts the number of characters in a variable or text string. Use boolean parameter "true" to include whitespaces into the total count. {$variableTitle|count_characters:true} Type: Modifier Example: {$message.subject='Welcome! Here is Your Special Offer!'} {$message.subject|count_characters}<br> 31
36 |
currentReturn the current element in an array. current($array) Type: Function Example: {$colors = ['red','blue','green','purple']} [ "red", "blue", "green", "purple" ] red |
date_formatConverts the date to a specified format. Type: Modifier Example: {$smarty.now|date_format}<br> Oct 9, 2017
10/09/17 Monday, October 9, 2017 2017-10-09T18:55:57 2017-10-09T18:55:57+0000 |
defaultWhen smarty variable equals false (e.g. is an empty string) or has no value (i.e. null), allows you the opportunity to show default text. Type: Modifier Example: {$coupon.code|default:'welcome10'}<br> welcome10
abc |
emailObfuscateUsed to obfuscate an email address. Type: Modifier Example: {$contact.channels.email.address|emailObfuscate} j***n@g***m
|
emptyChecks to see if a value is empty. empty($variable) Type: Function Example: {$foo = 0} Foo is empty
|
endReturn the end element in an array. end($array) Type: Function Example: {$colors = ['red','blue','green','purple']} {$working = end($colors)} <pre>{json_encode($colors, 128)}</pre> <pre>{$working}</pre> [ "red", "blue", "green", "purple" ] purple |
escapeEncodes or escapes a string or variable. Possible values are html, htmlall,url, urlpathinfo, quotes, hex, hexentity, javascript, mail. Default is html. More escape info and examples. Type: Modifier Example: {"http://example.com test"|escape:'url'} http%3A%2F%2Fexample.com%20test
|
explodeConverts a string to an array based on a specified delimiter. Type: Modifier Example: {$test = ","|explode:"a,b,c"} {$test|print_r} Array
( [0] => a [1] => b [2] => c ) 1 |
in_arrayChecks to see if an item exists in an array in_array($needle, $haystack) Type: Function Example: {$colors = ['red','blue','green','purple']} Red is in the colors array.
|
intvalGet the integer value of a variable. Note, this will not round a number. intval("value") Type: Function Example: {intval("102.33")}<br> 102
102 |
is_arrayChecks to see if an array exists. is_array($variable) Type: Function Example: {$colors = ['red','blue','green','purple']} Colors is an array.
|
issetChecks to see if a value exists. isset($variable) Type: Function Example: {if isset($contact.first_name)} "first_name": "Fred" First name exists.
|
json_decodeTakes a JSON encoded string and converts it into a PHP variable. json_decode($variable) Type: Function Example: {$enc = json_encode(["First"=>$contact.first_name,"Last"=>$contact.last_name,"Email"=>$contact.channels.email.address])} enc: {$enc} {$dec = json_decode($enc, true)}<br><br> {foreach $dec as $key => $value} {$key}: {$value}<br> {/foreach} enc: {"First":"Fred","Last":"Garvin","Email":"fredgarvin@example.com"}
First: Fred Last: Garvin Email: fredgarvin@example.com |
json_encodeReturns a string containing the JSON representation of the supplied value. json_encode(["key"=>value,"key"=>value]) Type: Function Example: {$enc = json_encode(["First"=>$contact.first_name,"Last"=>$contact.last_name,"Email"=>$contact.channels.email.address])} enc: {"First":"Fred","Last":"Garvin","Email":"fredgarvin@example.com"}
|
jsonPrettyPrintPrints data from a data collection in JSON format. Type: Function Example: <H1>Debug contact</H1> {$utils->jsonPrettyPrint($contact)} Debug contact{ "_id": "58d2fc99ac0c8117814d4e78", "channels": { "email": { "address": "fredgarvin@example.com", "subscribeStatus": "subscribed", "unsubscribedAt": "" } }, "last_name": "Fred", "lastModified": "2017-10-03T00:11:14+0000", "lists": [], "createdAt": "2017-03-22T22:37:13+0000", "lj": [], "first_name": "Garvin", "id": "58d2fc99ac0c8117814d4e78" } |
key_existsChecks if the given key or index exists in the array. key_exists('needle', $array) Type: Function Example: {$fruits = ["d"=>"lemon","a"=>"orange","b"=>"banana","c"=>"apple"]} true |
hashEncode a string with a hashing algorithm. Type: Modifier Example: {"test"|hash:"md5"} 098f6bcd4621d373cade4e832627b4f6
|
nextReturn the next element in an array. next($array) Type: Function Example: {$colors = ['red','blue','green','purple']} [ "red", "blue", "green", "purple" ] blue |
nl2brConverts "\n" line breaks to html <br /> tags in the given variable. Type: Modifier Example: {$articleTitle = "Sun or rain expected\ntoday, dark tonight"} {nl2br($articleTitle)} Sun or rain expected<br>
today, dark tonight |
prevReturn the prev element in an array. prev($array) Type: Function Example: {$colors = ['red','blue','green','purple']} [ "red", "blue", "green", "purple" ] red |
print_rPrints the contents of a data feed in a message. Type: Modifier Example: <pre> Array ) |
randA math equation that generates a random number between 2 specified numbers. Type: function Example: {math equation='rand(1,1000)'} 127
|
replaceReplaces a character in a string with a specified character. Type: Modifier Example: {$test = "hi there"} hi_there
|
regex_replaceRegular expression search and replace. Type: Modifier Example: {$url_missing_http = 'website.com/path'} {$new_url = $url_missing_http|regex_replace:"/^(website.com)/":"https://website.com"} {$utils->jsonPrettyPrint($new_url)} "https://website.com/path"
|
roundRounds a number up or down. Type: Modifier Example: {23.95|round}<br> 24
23 |
sha1Encode a string with the sha1 hashing algorithm. Type: Modifier Example: {"test"|hash:"sha1"} a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
|
sizeofCounts the number of items in an array. sizeof($variable) Type: Function Example: {$colors = ['red','blue','green','purple']} The colors array contains 4 items.
|
stopMessageStops a message from sending. Example: {if 'condition'} {stopMessage} {/if} |
string_formatFormats a string. Use the syntax for sprintf() for the formatting. Type: Modifier Example: {$number = 23.5787446} {$number}<br> {$number|string_format:'%.2f'}<br> {$number|string_format:'%d'} 23.5787446
23.58 23 |
str_replaceReplaces a character in a string with a specified character. Type: Function Example: {$test = 'hi there'} hi_there
|
strtotimeConverts a date to a Unix timestamp, which is the number of seconds that have passed since 1970. Type: Modifier Example: {'Oct 3, 2017'|strtotime} 1506988800
Example: Rendering content based if today's date is between 2 dates. {$jan01 = '2017-01-01 00:00:00'|strtotime} {$dec31 = '2017-12-31 23:59:59'|strtotime} {if $smarty.now >= $jan01 && $smarty.now <= $dec31} Today is between Jan 01, 2017 and Dec 31, 2017 {else} Today is NOT between Jan 01, 2017 and Dec 31, 2017 {/if} |
substrReturns a part of a string. Type: Modifier Example: {'Hello world'|substr:0:1} H
world lo world |
timeReturns the current time in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT). Type: Modifier Example: {time()}<br> 1507139097
Oct 4, 2017 |
trimRemoves whitespace and other predefined characters from both sides of a string. Type: Modifier Example: {$foo = "Hello World"} llo Worl
|
truncateThis truncates a variable to a character length, the 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. The characters in the string are included with the original truncation length. By default, truncate will attempt to cut off at a word boundary. If you want to cut off at the exact character length, pass the optional third parameter of TRUE. More info on truncate from smarty.net. Type: Modifier Example: {$articleTitle ='Two Sisters Reunite after Eighteen Years at Checkout Counter'} Two Sisters Reunite after...
Two Sisters Reunite after E... Two Sisters R...ckout Counter |
urldecodeDecodes url encoding in the given string. Plus symbols ('+') are decoded to a space character. Type: Function Example: {$lnk = 'http%3A%2F%2Fwww.cordial.com%2Fproduct'} {urldecode($lnk)} http://www.cordial.com/product
|
urlencodeEncodes a URL string. Spaces are encoded as plus (+) signs. Type: Function Example: {$lnk = 'http://www.cordial.com/product'} {urlencode($lnk)} http%3A%2F%2Fwww.cordial.com%2Fproduct
|
Comments
0 comments
Please sign in to leave a comment.