Re: [SMARTY] modifiers functions

From: Date: Sun, 13 Mar 2005 01:38:23 +0000
Subject: Re: [SMARTY] modifiers functions
References: 1 2  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-12320@lists.php.net to get a copy of this message
Hi, again! Whoops! I did not test the script, I just typed it :-) The remaining string value does not get computed correctly (20 chars minus string length). Here is a version that *works*. (Sorry about that, I will first test my replies from now on...) BTW, our friend in this case is the "math" function. there might be a better way to do this, I'm just in a bit of a hurry right now :-) <!-- Smarty Code Begins --> <hr /> {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-&gt;[{$str1|truncate:20:"..."}]&lt;-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 /> {assign var="strremain" value=$strlen} {math equation="20-x" x=$strlen assign="remains"} String begins-&gt;[{$str2}{section name="space" loop=$remains}&nbsp;{/section}]&lt;-String ends {/if} <hr /> <!-- Smarty Code Ends --> Enjoy, Werner Werner wrote:
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-&gt;[{$str1|truncate:20:"..."}]&lt;-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-&gt;[{$str2}{section name="char" loop=20-$strlen}&nbsp;{/section}]&lt;-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


« previous php.smarty.general (#12320) next »