Files
smarty/docs/designers/language-modifiers/language-modifier-split.md
Simon Wisselink 41d80b99ac Implemented support for substr, implode and json_encode as modifiers. (#940)
* Implemented support for substr, implode and json_encode as modifiers. Fixes #939
* Added split and join in favor of explode and implode modifiers.
* Documented all available modifiers
2024-02-26 14:35:19 +01:00

1.0 KiB

split

Splits a string into an array, using the optional second parameter as the separator.

Basic usage

For $chars populated with 'abc', the following will produce a html list with 3 elements (a, b and c).

<ol>
    {foreach $chars|split as $char}
        <li>{$char|escape}</li>
    {/foreach}
</ol>

Parameters

Parameter Type Required Description
1 string No separator used to split the string on. Defaults to empty string, causing each character in the source string to be separate.

Examples

For $ids populated with '1,2,3', the following will produce a html list with 3 elements (1, 2 and 3).

<ol>
    {foreach $ids|split:',' as $id}
        <li>{$id|escape}</li>
    {/foreach}
</ol>