|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
pennix Smarty n00b
Joined: 18 Mar 2008 Posts: 3
|
Posted: Mon Oct 31, 2011 8:30 am Post subject: truncate issue |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Nov 01, 2011 11:58 am Post subject: |
|
|
Truncate does run for each iteration individually.
I assume the products array does not contain data. |
|
Back to top |
|
pennix Smarty n00b
Joined: 18 Mar 2008 Posts: 3
|
Posted: Tue Nov 01, 2011 12:32 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Nov 01, 2011 2:05 pm Post subject: |
|
|
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 |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
Posted: Tue Nov 01, 2011 2:22 pm Post subject: |
|
|
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 |
|
ema Smarty n00b
Joined: 01 Nov 2011 Posts: 4
|
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Nov 02, 2011 8:21 pm Post subject: |
|
|
can you make a simple demonstration with php/smarty and post it here? |
|
Back to top |
|
|
|
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
|