Hi, I wish to truncate some content to a certain character count. I found that I can do this like this...
{content|truncate:250:"... Read more":true}
However I want the Read more to be a link, for example...
{content|truncate:250:"... <a href="http://link.com">Read more</a>":true}
But... the set of "double quotes" in the link html causes problems. Is there a way to escape these chararcter so they are correctly displayed in the browser?
Also, is there a way to truncate to a word count rather than a chararcter count so the truncate does not cut words off part way through?
Thanks, Steven
truncate content to certain character count
Re: truncate content to certain character count
how about
You might also want to check the smarty documentation:
http://www.smarty.net/docsv2/en/languag ... uncate.tpl
Code: Select all
{content|truncate:250:'... <a href="http://link.com">Read more</a>'}
http://www.smarty.net/docsv2/en/languag ... uncate.tpl
This determines whether or not to truncate at a word boundary with FALSE, or at the exact character with TRUE.
Re: truncate content to certain character count
Many thanks, thats worked fine.
I also need to know how to insert a smarty tag within a smarty tag. Is that called Nesting?
for example:
{content|truncate:250:'... <a href="http://link.com">{title}</a>'}
The above with a second set of curly braces {title} does not work. I did look on the smarty help pages but could not find anything.
Steven
I also need to know how to insert a smarty tag within a smarty tag. Is that called Nesting?
for example:
{content|truncate:250:'... <a href="http://link.com">{title}</a>'}
The above with a second set of curly braces {title} does not work. I did look on the smarty help pages but could not find anything.
Steven
Re: truncate content to certain character count
The exact same example is given here http://wiki.cmsmadesimple.org/index.php ... riables.3F
-
- Support Guru
- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
Re: truncate content to certain character count
Smarty tags can't be nested in the way you'd think Smarty is smart, just not that smart. (at least not smarty 2).
You need to build the string that you want to use for your 'read more' stuff, and assign that to a smarty variable, then use the smarty variable inside the next call... Smarty gives you at least two tags to do this: {capture} and {assign} ... capture is the easiest to deal with.
{capture assign='foo'}<a href="http://foo.com">{title}</a>{/capture}
{content|truncate:256:$foo}
You need to build the string that you want to use for your 'read more' stuff, and assign that to a smarty variable, then use the smarty variable inside the next call... Smarty gives you at least two tags to do this: {capture} and {assign} ... capture is the easiest to deal with.
{capture assign='foo'}<a href="http://foo.com">{title}</a>{/capture}
{content|truncate:256:$foo}
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.