The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
for loop in a template?
I'm sure I'm missing something blindingly simple and/or obvious here but I can't figure it out or find the answer.
If in my php file i create a variable (e.g. $stuff='nonsense'), then in the associated vbulletin template file I can just use $stuff and it prints out 'nonsense' for me. If however I have an array variable in my php file (e.g. $stuff[a]='nonsense'; $stuff[aj]='whatever'; $stuff[klm]='other thing') how can i write a for loop to print out the components of $stuff? i don't know in advance what keys are being used, or how many there are. I could just create all the html code within php and put it in a single variable to use in the vbulletin template but I feel like I ought to be able to do it straight in the template, which would be clearer coding. thanks kirsty OK, I've sorted it out. It's fairly obvious once you find the solution but not terribly easy to find when you don't know the solution! There is no "foreach" or any similar looping construct in vbulletin templates. What you do is loop a template from the php code. So in your php file you do something like foreach ($stuff as $key => $value) { eval('$processedstuff .= "' . fetch_template('loopy_template') . '";'); } loopy_template contains the html code you want to use over and over again. you can use $key and $value in the loopy_template code. You can then use $processedstuff in your main template that you eval later on. hope this helps someone else out kirsty |
#2
|
||||
|
||||
appreciate the update :up:
|
#3
|
|||
|
|||
This helped me a lot an saved me work!! Thank you very much for sharing
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|