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

 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty 3
View previous topic :: View next topic  
Author Message
kaitlyn2004
Smarty Regular


Joined: 26 Apr 2007
Posts: 47

PostPosted: Wed Mar 17, 2010 5:51 pm    Post subject: str_repeat problem? Reply with quote

So before I would use:

Code:
{' '|str_repeat:4*$depth}


but now with smarty 3, my output is just a "0" and I had to change to:

Code:
{str_repeat(' ',4*$depth)}


No problem myself with this change, but is this perhaps a bug.. or what changed/what did I miss?
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Wed Mar 17, 2010 6:45 pm    Post subject: Reply with quote

As Smarty 2 did handle mathematical expressions not in a general way parsing results may differ in Smarty3.

Smarty3 did parse it as

{(' '|str_repeat:4)*$depth}

correct syntax for this case would be


Code:
{' '|str_repeat:(4*$depth)}
Back to top
View user's profile Send private message
Aristophan
Smarty Regular


Joined: 10 Jan 2011
Posts: 84

PostPosted: Sat Oct 06, 2012 6:50 pm    Post subject: Reply with quote

May I just hook this thread up into mind...

Is there something wrong using
Code:
 {' '|@str_repeat:$folder.depth*2}

with Smarty3 ? With current 3.1.12 we get 0, where should be nothing.
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Sat Oct 06, 2012 8:54 pm    Post subject: Reply with quote

In Smarty3 resolving a modifer has higher priority as multiplication. So you have to use parenthesis to get the multiplication executed first.

Code:
{' '|str_repeat:($folder.depth*2)}
Back to top
View user's profile Send private message
Aristophan
Smarty Regular


Joined: 10 Jan 2011
Posts: 84

PostPosted: Sun Oct 07, 2012 8:40 am    Post subject: Reply with quote

Thanks Uwe!
That was the first I tried... without luck, ...but as it returns, I did not change the right tpl's, while in a testcase. Issue solved!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty 3 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