Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Display Certain Number of Characters

 
Post new topic   Reply to topic    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
craigfh
Smarty n00b


Joined: 23 Feb 2009
Posts: 4

PostPosted: Mon Feb 23, 2009 1:57 pm    Post subject: Display Certain Number of Characters Reply with quote

I am trying to only display a certain number of characters from dbase field otherwise it is way to long.

For example I have a description that is 500 characters and only want to diplsy the fisrt 30.

Is there a way to take this?

{$list[itm].id}

and maybe add a pipe and the number of characters to display or do I have to do it in PHP another way.

{$list[itm].description | charcters:30;}


thanks
Craig
Back to top
View user's profile Send private message
jothirajan
Smarty Pro


Joined: 06 Feb 2009
Posts: 114
Location: India

PostPosted: Mon Feb 23, 2009 2:04 pm    Post subject: Reply with quote

HP


Code:
{$list[itm].description | stripslashes|wordwrap:30:"\n":true}


>>> This will show all the result in the next|next row


Code:

{$list[itm].description|truncate:30}
{$list[itm].description|truncate:30:""}
{$list[itm].description|truncate:30:"---"}
{$list[itm].description|truncate:30:"":true}
{$list[itm].description|truncate:30:"...":true}


>>> This will help for you....

Get me if you want more...

Happy coding

JO Laughing
Back to top
View user's profile Send private message Send e-mail
craigfh
Smarty n00b


Joined: 23 Feb 2009
Posts: 4

PostPosted: Mon Feb 23, 2009 3:33 pm    Post subject: Reply with quote

{$list[itm].description | stripslashes|wordwrap:30:"\n":true}

In the above case does it mean it will just not show any text after 30 characters?

Because this is a drop down menu if there is more than 30 charecters is screws up the menu.

I am trying to only have one row of text no longer the 30.

thanks for your help.
Craig
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7365
Location: Lincoln Nebraska, USA

PostPosted: Mon Feb 23, 2009 5:13 pm    Post subject: Reply with quote

use the truncate modifier.
Back to top
View user's profile Send private message Visit poster's website
jothirajan
Smarty Pro


Joined: 06 Feb 2009
Posts: 114
Location: India

PostPosted: Tue Feb 24, 2009 5:48 am    Post subject: Reply with quote

craigfh wrote:
{$list[itm].description | stripslashes|wordwrap:30:"\n":true}

In the above case does it mean it will just not show any text after 30 characters?

Because this is a drop down menu if there is more than 30 charecters is screws up the menu.

I am trying to only have one row of text no longer the 30.

thanks for your help.
Craig


>>> Use the above said truncate functionality......This is good for you

Thanks
Happy coding
Back to top
View user's profile Send private message Send e-mail
jothirajan
Smarty Pro


Joined: 06 Feb 2009
Posts: 114
Location: India

PostPosted: Fri Dec 17, 2010 10:54 am    Post subject: Reply with quote

{$RES_Q_RECORD_SINGLE.0.page_description|truncate:230|wordwrap:15:"\n":true}

>> Will also help
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Tips and Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP