[Smarty]Summary of array and string counting

Get count of elements in array

For example, to get the number of elements in an array $loop:

{$loop|@count}

When count is used in the if statement

{ if count($loop) > 0 }
    $loop has at least 1 element
{/if}

 

Counting strings

Get the number of characters in a variable

{assign var="hoge" value="Hello World"}

{$hoge}
{$hoge|count_characters}
{$hoge|count_characters:true}  //White Space characterを含むかどうか

//Output data
Hello World
10
11

In addition to strings, paragraphs, sentences, words, and so on are also provided with qualifiers.

count_paragraphs
count_sentences
count_words

Smarty Recommended Books

Smarty had only old books, but the following are recommended for getting started.
Smarty PHP Template Programming and Applications