Quote:
Originally Posted by xgarb
how do I make so I can choose the number of characters to show from the template? IE something like {model.brief_description:ShortenText(100)} to show 100 characters.
|
I would just create a plain method with two arguments and used it in the template:
PHP Code:
protected function shortenText($string, $length)
{
return substr($string, 0, strrpos(substr($string, 0, $length), ' ')) . '...';
}
Code:
{**
* @ListChild (list="itemsList.newsMessages.customer.top.row", weight="250")
*}
<span class='brief'>{shortenText(model.brief_description,200)}</span> <a href="{buildURL(#news_message#,##,_ARRAY_(#id#^model.id))}">Read more</a>
However, I believe you don't need this method in _every_ widget on the page. So, it makes sense to put it into the widget class where you need it instead of decorating the base \XLite\View\AView class.