Re: [SMARTY] modifiers functions
| From: | Werner | Date: | Sun, 13 Mar 2005 01:18:04 +0000 |
| Subject: | Re: [SMARTY] modifiers functions | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-12319@lists.php.net to get a copy of this message | ||
Hi Nayra!
Here you go:
<!-- Smarty Code Begins -->
{assign var="str1" value="This is a long string, more than twenty characters long."}
{assign var="str2" value="A short string."}
{* first the long string demo :-) *}
{assign var="strlen" value=$str1|count_characters}
{if ($strlen) >= 20}
The string is <b>longer</b> than 20 characters. Here follows the string truncated to 20 characters:<br />
{* Here follows truncation *}
String begins->[{$str1|truncate:20:"..."}]<-String ends
{/if}
<hr />
{* now we do the short string demo :-) *}
{assign var="strlen" value=$str2|count_characters}
{if ($strlen) < 20}
The string is <b>shorter</b> than 20 characters. Here follows the string padded with spaces up to 20 characters:<br />
String begins->[{$str2}{section name="char" loop=20-$strlen} {/section}]<-String ends
{/if}
<!-- Smarty Code Ends -->
Have a nice day :-)
Werner
Nayra Quesada wrote:
Hi! I'm new working with Smarty and I have found it so much powerful. I'm spanish, so please write me in an esay english. :-) Well, I have a problem. I have a variable which contents a string and I want to cut it until 20 characters. If its lenght es less than 20 characters I would like to add space characters to make its lenght bigger, just 20 characters. I have seen modifiers function truncate, but I nedd some else. COul you tell some idea? Preferly without create a new modifier function. Thanxs!!!! :D