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

Counting Vars

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


Joined: 23 Jan 2004
Posts: 3

PostPosted: Fri Jan 23, 2004 4:39 pm    Post subject: Counting Vars Reply with quote

Imagine the following smarty template...

Code:
....
{$TEXT} {$MISC} {$TEXT}
...
{$LOG} {$TEXT}
...
{$MISC} {$TEXT}
...


It's completly random text and has nothing to do with cycles. Typically when it's time to assign every $TEXT will get the same value and so on. Is there a way on the programmers side to count this vars?

Something like $smart->vars["TEXT"][n], $smart->vars["LOG"][n], $smart->vars["MISC"][n] etc.

This because i have a xml file with something like:
Code:
<text>blabla</text>
<text>blabla</text>
<text>blabla</text>
<misc>blabla</misc>
<misc>blabla</misc>
<log>blabla</log>
Back to top
View user's profile Send private message
messju
Administrator


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

PostPosted: Fri Jan 23, 2004 7:10 pm    Post subject: Reply with quote

hmm. i'm not sure if i understood what you want.

if you only have simple-vars, you could probably register a prefilter that uses preg_match() to look for "{$...}"-elements.

do you want to count the occurrence in the template-source or in the template's output? (a prefilter would work on the source).
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Psiwar
Smarty n00b


Joined: 23 Jan 2004
Posts: 3

PostPosted: Fri Jan 23, 2004 7:37 pm    Post subject: Reply with quote

On the source. Well i figured as much... i will use a pre-filter to build an indexed array and then parse the xml with SAX (to build a similar array).

I think it would be a nice function to add to smarty. Something that walks the source template and then builds an associative array in the format of $array["var_name"][n]. It would make it easier for the programmer and it would removed much of the cycles from smarty templates.
Back to top
View user's profile Send private message
messju
Administrator


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

PostPosted: Sun Jan 25, 2004 4:11 pm    Post subject: Reply with quote

sorry i don't get it.

what do you mean by '$array["var_name"][n]' ? you mean a mapping variable-name to count of occurrences of this variable?

i really don't know anybody else who has use for that than you.

which cycles would be removed? i think cpu-cycles would be added to build that array.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Psiwar
Smarty n00b


Joined: 23 Jan 2004
Posts: 3

PostPosted: Tue Feb 03, 2004 5:49 pm    Post subject: Reply with quote

I was just thinking of template cycles.

Anyway, i made it to be as simple as:

$tpl->assign('somevar', $xml->DATA['somevar']);

where $xml->DATA['somevar'] is an array with all instances of a certain tag. Then it's just a matter of using {$somevar[0]}, {$somevar[1]}, etc or using a cycle in the template. (that i was trying to avoid)
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