View Single Post
  #3  
Old 11-19-2015, 11:43 PM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: Truncating text with an Output Filter

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($string0strrpos(substr($string0$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.
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote