Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

truncate issue

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
pennix
Smarty n00b


Joined: 18 Mar 2008
Posts: 3

PostPosted: Mon Oct 31, 2011 8:30 am    Post subject: truncate issue Reply with quote

Hello,
I'm having the following code :

Code:
 {section name=test loop=$obj->products}
      {$obj->products[test].main|truncate:100}
{/section}


What I want to do is to display the first 100 characters of each 'main' filed in the loop.
However it displays only 100 characters and then it leaves blank all the rest.
For example it displays:
main1: containing 30chars
main2: containing 50chars
main3: containing 20chars
main4:empty
main5: empty
and so on..
Any suggestions of how I can make this work?
Thanks in advance.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Nov 01, 2011 11:58 am    Post subject: Reply with quote

Truncate does run for each iteration individually.

I assume the products array does not contain data.
Back to top
View user's profile Send private message
pennix
Smarty n00b


Joined: 18 Mar 2008
Posts: 3

PostPosted: Tue Nov 01, 2011 12:32 pm    Post subject: Reply with quote

Hello,
The array contains data , the issue is that it seems that truncate is working only until it reaches the limitation of the 100 characters as a sum of characters.
In general saying I haven't seen this kind of problem again and I have used the 'truncate' function many times, that's way I'm desperate of working this out.
Thanks again,
P.
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Tue Nov 01, 2011 2:05 pm    Post subject: Reply with quote

test the original data too, it may not be truncate that is the problem.

Code:
{section name=test loop=$obj->products}
      orig: {$obj->products[test].main}
      trunc: {$obj->products[test].main|truncate:100}
{/section}
Back to top
View user's profile Send private message Visit poster's website
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Tue Nov 01, 2011 2:22 pm    Post subject: Reply with quote

Code:
{$foo = [
  "hello world. I'm totally long and stuff. I need to be truncated at some point. Can you help me with that? is It possible, yes?",
  "hello world. I'm totally long and stuff. I need to be truncated at some point. Can you help me with that? is It possible, yes?",
  "hello world. I'm totally long and stuff. I need to be truncated at some point. Can you help me with that? is It possible, yes?",
  "hello world. I'm totally long and stuff. I need to be truncated at some point. Can you help me with that? is It possible, yes?",
  "hello world. I'm totally long and stuff. I need to be truncated at some point. Can you help me with that? is It possible, yes?",
  "hello world. I'm totally long and stuff. I need to be truncated at some point. Can you help me with that? is It possible, yes?"
]}
{foreach $foo as $f}
  {$f|truncate:50}<br />
{/foreach}
prints
Code:
hello world. I'm totally long and stuff. I need...
hello world. I'm totally long and stuff. I need...
hello world. I'm totally long and stuff. I need...
hello world. I'm totally long and stuff. I need...
hello world. I'm totally long and stuff. I need...
hello world. I'm totally long and stuff. I need...


(Smarty 3.1.4)
_________________
Twitter
Back to top
View user's profile Send private message Visit poster's website
ema
Smarty n00b


Joined: 01 Nov 2011
Posts: 4

PostPosted: Wed Nov 02, 2011 12:22 pm    Post subject: Reply with quote

Same problem here. I use modifier.html_substr.php instead: http://www.smarty.net/forums/viewtopic.php?t=533
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Wed Nov 02, 2011 8:21 pm    Post subject: Reply with quote

can you make a simple demonstration with php/smarty and post it here?
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General 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