Truncate in Smarty

Truncate in Smarty

This truncates a variable to a character length, default is 80. As an optional second parameter, we 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 we want to cut off at the exact character length, pass the optional third parameter of true.

Example

<?php

$smarty->assign(’input’, ‘This is test string which use truncate.’);

?>

In template we can have like,

{$input}

{$input|truncate}

{$input|truncate:30:”—”}

{$input|truncate:30:”…”:true}

The output will be as follows:

This is test string which use truncate.

This is test string which use truncate.

This is test—

This is test st…

Leave a Reply


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.