PHP Functions Available for Kuroco's Smarty
You can use Smarty plugins for custom functions or batch processes in Kuroco.
This document provides the list of the PHP functions that can be used as modifiers for variables.
Available PHP Functions
if Statement
The following PHP functions can be used with the {if} statement in Kuroco's Smarty.
PHP Function | Description |
---|---|
is_null | Checks if a variable is null |
count | Counts all elements in an array or Countable object |
is_array | Checks if a variable is an array |
in_array | Checks if a value exists in an array |
isset | Checks if a variable is declared and is not null |
is_object | Checks if a variable is an object |
Example
{if is_null($hoge)}
$hoge is null.
{/if}
Modifiers
The following PHP functions can be used as modifiers for variables in Kuroco's Smarty.
PHP Function Name | Description |
---|---|
array_column | Returns the values from a single column of an input array |
array_key_exists | Checks if a specified key or index exists in an array |
array_keys | Returns all the keys of an array, or a subset of the keys |
array_merge | Merges one or more arrays |
array_pop | Removes an element from the end of an array |
array_push | Pushes one or more elements onto the end of an array |
array_reverse | Returns an array with elements in reverse order |
array_shift | Removes the first element from an array and returns it |
array_slice | Extracts a slice of an array |
array_unique | Removes duplicate values from an array |
array_values | Returns all the values of an array |
arsort | Sorts an array in reverse order, maintaining the key to element relationship |
asort | Sorts an array in ascending order, maintaining the key to element relationship |
base64_decode | Decodes data encoded with MIME base64 |
base64_encode | Encodes data with MIME base64 |
explode | Splits a string by a string |
filter_var | Filters a variable with a specified filter |
floor | Rounds a number down to the nearest integer |
html_entity_decode | Converts HTML entities to their corresponding characters |
htmlspecialchars_decode | Converts special HTML entities back to characters |
http_build_query | Generates a URL-encoded query string |
implode | Joins array elements with a string |
intval | Returns the integer value of a variable |
is_array | Checks if a variable is an array |
is_numeric | Checks if a variable is a number or a numeric string |
json_decode | Decodes a JSON string |
json_encode | Returns a JSON encoded string |
key | Fetches a key from an array |
krsort | Sorts an array by key in reverse order |
ksort | Sorts an array by key in ascending order |
max | Returns the highest value in an array |
mb_convert_encoding | Converts a string from one character encoding to another |
mb_convert_kana | Converts Kana characters to a specific Kana type |
mb_strimwidth | Truncates a string to a specified width |
mb_stripos | Finds the position of the first occurrence of a case-insensitive string within another string |
mb_strlen | Returns the length of a string |
mb_strpos | Finds the position of the first occurrence of a string inside another string |
mb_strwidth | Returns the width of a string |
mb_substr | Returns part of a string |
md5 | Calculates the MD5 hash of a string |
min | Returns the lowest value in an array |
mt_rand | Generates a random number using the Mersenne Twister random number generator |
nl2br | Inserts HTML line breaks before all newlines in a string |
number_format | Formats a number with grouped thousands |
parse_url | Parses a URL and returns its components |
pathinfo | Returns information about a file path |
property_exists | Checks if an object or class has a property |
range | Creates an array containing a range of elements |
rawurldecode | Decodes a URL-encoded string |
round | Rounds a float to the nearest integer |
rsort | Sorts an array in reverse order |
shuffle | Shuffles an array |
sort | Sorts an array in ascending order |
str_pad | Pads a string to a certain length with another string |
strip_tags | Strips HTML and PHP tags from a string |
stripos | Finds the position of the first occurrence of a string inside another string, case-insensitive |
strlen | Returns the length of a string |
strpos | Finds the position of the first occurrence of a string inside another string |
strstr | Finds the position of the first occurrence of a string inside another string |
strtolower | Converts a string to lowercase |
strtotime | Converts an English textual datetime description to a Unix timestamp |
strtoupper | Converts a string to uppercase |
strval | Returns the string value of a variable |
substr | Returns a part of a string |
trim | Removes whitespace from the beginning and end of a string |
unset | Unsets a specified variable |
urlencode | URL-encodes a string |
- Specify the variable as the first argument of the function and the function name as the modifier. For the second and subsequent arguments, write them after the modifier separated by a colon (
:
). - If the variable is an array, prefix the function name with an
@
sign. - Please refer to the List of Constants Available in Kuroco for the PHP predefined constants used in functions.
Example (for array_column)
{* Example of a record set returned from a database *}
{assign_array var="records" values=""}
{assign_array var="record" values=""}
{append var="record" index="id" value=2135}
{append var="record" index="first_name" value="John"}
{append var="record" index="last_name" value="Doe"}
{append var="records" value=$record}
{assign_array var="record" values=""}
{append var="record" index="id" value=3245}
{append var="record" index="first_name" value="Sally"}
{append var="record" index="last_name" value="Smith"}
{append var="records" value=$record}
{assign_array var="record" values=""}
{append var="record" index="id" value=5342}
{append var="record" index="first_name" value="Jane"}
{append var="record" index="last_name" value="Jones"}
{append var="records" value=$record}
{assign_array var="record" values=""}
{append var="record" index="id" value=5623}
{append var="record" index="first_name" value="Peter"}
{append var="record" index="last_name" value="Doe"}
{append var="records" value=$record}
{* Specify the variable as the first argument of the function and the function name as the modifier. For the second and subsequent arguments, write them after the modifier separated by a colon (`:`) *}
{* If the variable is an array, prefix the function name with an at sign (`@`) *}
{assign var="first_names" value=$records|@array_column:'first_name'}
{$first_names|@debug_print_var}
Output
Array (4)
0 => "John"
1 => "Sally"
2 => "Jane"
3 => "Peter"
Example (for str_pad)
{assign var=input value="Alien"}
{assign var=output value=$input|str_pad:10:"_":$smarty.const.STR_PAD_BOTH}
{$input|debug_print_var}
{$output|debug_print_var}
Output
"Alien"
"__Alien___"
Support
If you have any other questions, please contact us or check out Our Slack Community.