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

{math} with an array count?

 
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
dygel
Smarty n00b


Joined: 22 Nov 2006
Posts: 3

PostPosted: Wed Nov 22, 2006 5:21 pm    Post subject: {math} with an array count? Reply with quote

I'm doing some screwy work with tabindexes on a form. There's a master section with sub blocks, which are presented below. The sub blocks feed total fields on the master form, so the tabindex path takes you through fields in the master till you get to the total line, drops you down to the sub block, walks you through that, and takes you up to the next line in the master form.

Code side, I'm trying to do some math to advance my tab index count ahead by the number of objects in the array used to build the sub block (in this case $products[1]) plus one.

Trick is, I'm not finding a simple way to do this with out-of-the-box smarty functions. I can't use count(), since this isn't an {if}. I tried using $products[1]|count as a modifier -- that didn't work either.

Anyone have any suggestions or would I be stuck writing a custom function or modifier?
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Wed Nov 22, 2006 5:29 pm    Post subject: Reply with quote

count() should work fine inside {if}.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
dygel
Smarty n00b


Joined: 22 Nov 2006
Posts: 3

PostPosted: Wed Nov 22, 2006 5:35 pm    Post subject: Reply with quote

messju wrote:
count() should work fine inside {if}.


Inside {if}, it would. I'm using {math}.
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Nov 22, 2006 5:40 pm    Post subject: Reply with quote

For a modifier, you pass an entire array using @:

{$products[1]|@count}
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Wed Nov 22, 2006 5:44 pm    Post subject: Reply with quote

dygel wrote:
Inside {if}, it would. I'm using {math}.


arg! misread the "isn't".

you can do something like: {math equation="a+1" a=$foo|@count}
Back to top
View user's profile Send private message Send e-mail Visit poster's website
dygel
Smarty n00b


Joined: 22 Nov 2006
Posts: 3

PostPosted: Wed Nov 22, 2006 5:54 pm    Post subject: Reply with quote

boots wrote:
For a modifier, you pass an entire array using @:
{$products[1]|@count}


That did what I needed. Thanks for the tip.
Back to top
View user's profile Send private message
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