|
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 |
Psiwar Smarty n00b
Joined: 23 Jan 2004 Posts: 3
|
Posted: Fri Jan 23, 2004 4:39 pm Post subject: Counting Vars |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Fri Jan 23, 2004 7:10 pm Post subject: |
|
|
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 |
|
Psiwar Smarty n00b
Joined: 23 Jan 2004 Posts: 3
|
Posted: Fri Jan 23, 2004 7:37 pm Post subject: |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Sun Jan 25, 2004 4:11 pm Post subject: |
|
|
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 |
|
Psiwar Smarty n00b
Joined: 23 Jan 2004 Posts: 3
|
Posted: Tue Feb 03, 2004 5:49 pm Post subject: |
|
|
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 |
|
|
|
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
|