modifier.truncate_html_safe.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2020 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
12 
13 /**
14  * Truncate a text while preserving words and html tags.
15  *
16  * Example:
17  * @code
18  * <p class="teaser">{$text|truncate_html_safe}</p>
19  * @endcode
20  *
21  * @param $text The text to truncate
22  * @param $length The number of chars to truncate to (default: 100)
23  * @param $suffix The suffix to append (default: …)
24  * @return String
25  */
26 function smarty_modifier_truncate_html_safe($text, $length=100, $suffix='…') {
27  return StringUtil::cropString($text, $length, $suffix);
28 }
29 ?>
StringUtil provides support for string manipulation.
Definition: StringUtil.php:18