PDA

View Full Version : Question: How do you display custom (non-vb) array variables in templates?


Attilitus
01-05-2007, 02:33 AM
I am sure it is something silly, either that or it can't be done at all.

This is what I mean:

I have a script that allows me to:

In php I can get the right value by putting:

$myarray[$increment]->fieldtodisplay

Which will pull all fields from the result list that I queried in the previous function.

Now whenever I try to add the above variable into vbulletin's templating system it will only output the first value. The query itself is working fine, it is just the display end of it. For example if I go to the "next page" it will display the correct FIRST ENTRY of that page.

Entry into template is: {$myarray[$increment]->fieldtodisplay}

Is there anyway to get vbulletin templates to correctly display ALL values of custom arrays?

I am sure it is one of those things that is either incredibly simple, or just a matter of "it doesn't work, sorry" but, it would save me some time if someone could give me a heads up either way.

Thanks!

~Attilitus


Edit:

Here are some examples of what I want to do:

<?php

// define array
$artists = array('Metallica', 'Evanescence', 'Linkin Park', 'Guns n Roses');
// loop over it and print array elements
for ($x = 0; $x < sizeof($artists); $x++) {
echo '<li>'.$artists[$x];
}

?>

</ul>
</body>
</html>

When you run this script, here's what you'll see:

My favourite bands are:

* Metallica
* Evanescence
* Linkin Park
* Guns n Roses

Taken right off of zend.com

Now, putting an echo function within the for() loop displays all values, however, defining a variable within the for () loop will only store one variable to be pulled by the template. Since I want to use a vbulletin template to display the values, this is obviously a problem.

Can anyone at least point me in the right direction?

noppid
01-05-2007, 03:20 PM
When you do a loop like that for elements of a list, it's usually done with a bits template.

So, my suggestion would be to have a template like so...


<li>$artist</li>


Then in the loop...

$artistbits = '';
$artists = array('Metallica', 'Evanescence', 'Linkin Park', 'Guns n Roses');
// loop over it and print array elements
for ($x = 0; $x < sizeof($artists); $x++)
{
$artist = $artists[$x];
eval('$artistbits .= "' . fetch_template('artist_bit') . '";');
}

Then later when you call the main tempate...


<ul>
$artistbits
</ul>


The problem you are having seems to be trying to display an object in the templates. But I'm not 100% sure. That's a guess.

Attilitus
01-05-2007, 07:09 PM
First off thanks for your response!

However, I can't seem to get that code to work...

Is there something that I am missing? I set everything up "exactly" as you said.

Edit:

Nevermind, it is working now, I was working with templates that were being overriden by child styles when testing.

Thanks! I had been trying to figure this out all last night. :)

noppid
01-05-2007, 08:57 PM
Glad to help. It's even better when the help get ya there.

Good job!