-
☆ A M B ☆
- 2,213 Posts
I would suggest putting stripTags first, otherwise you can end up with "<br " where you might not want it. As for eliminating cutoff words, I think you would need to build something custom.
Hope that helps.
You could create your own custom output modifier. Something like this (untested):
[[+content:striptags:ellipsis=`300`:WholeWords]]
<?php
/* WholeWords snippet */
$pos = strrpos($input, ' ');
return substr($input, 0, $pos);
Thanks Bob,
It works! I replaced ellipsis with limit and used your snippet.
[[+content:striptags:limit=`300`:WholeWords]]
I'm glad to hear it worked.
Brilliant solution.
AMDbuilder's warning to use the striptags modifier seems important too, though I notice from trial-and-error that paragraph tags get closed automatically. Does anyone know how important it is to use striptags i.e. how badly you can break your page without it? And is the behaviour of the ellipsis and limit modifiers fully documented anywhere?
David Walker
Principal, Shorewalker DMS
Phone: 03 8899 7790
Mobile: 0407 133 020
It really depends on what's in the selected section (the part up to the limit). If you don't use striptags at all, you can end up with an unclosed <div>, <img>, or <a href> tag that will either mess up the rest of the page or make it disappear when the browser tries to interpret the rest of the page as a URL.
If you use striptags, it's important to put it first because otherwise, a) the length of the return string will be unreliable because the tag characters will be counted and b) if a start tag is in the selection and its closing tag isn't, striptags can eat the rest of your content looking for it.
As for the behavior of the two functions, the limit modifier simply counts all characters and returns the string up to the number you specify. The ellipsis modifier does exactly the same thing and then appends '…' ('…') before returning the string.