View Full Version : [TEMPLATE SYNTAX] vb:each from piece of an array

12 Dec 2009, 18:35
I have an array:

$binaries = array(
0 => array(
'subject' => 'Subject 1',
'binaryid' => 1,
'groups' => array('alt.binaries.teevee', 'alt.binaries.multimedia')
1 => array(
'subject' => 'Subject 2',
'binaryid' => 2,
'groups' => array('alt.binaries.xvid')

I then render a template:

$templater = vB_Template::create('ng_managebinaries');
$templater->register('navbar', $navbar);
$templater->register('binaries', $binaries);

In my template I can use this code fine:

<vb:each from="binaries" value="binary">
{vb:raw binary.subject}
{vb:raw binary.binaryid}

But this template code would give me an error:

<vb:each from="binaries" value="binary">
{vb:raw binary.subject}
{vb:raw binary.binaryid}
<vb:each from="binary.groups" value="group">
{vb:raw group}

The error that I get is:
Warning: Invalid argument supplied for foreach() in D:\Sites\vbdev\includes\class_core.php(3917) : eval()'d code on line 142

Does anybody know what would be the correct syntax to use for this (from="binary.groups" is probably incorrect)? Or have I found a vBulletin bug?

--------------- Added 1260659509 at 1260659509 ---------------

I figured this out.
I must use this:

<vb:each from="binaries" value="binary">
{vb:raw binary.subject}
{vb:raw binary.binaryid}
<vb:each from="binary['groups']" value="group">
{vb:raw group}

(from="binary['groups']" instead of from="binary.groups")
Just incase anyone is wondering, or searching for the same answer.

Thanks to whoever looked.

--------------- Added 1260659823 at 1260659823 ---------------

That info also comes in handy if you're trying to use any arrays inside of a curly bracket.
For example:

{vb:rawphrase {vb:raw item['phrase']}}

02 May 2010, 23:47
THank ya.

I thought it was dot syntax, too, heh.

Anyone know why it's not?

03 May 2010, 05:53
Or have I found a vBulletin bug?
Yes you did.


16 Jun 2011, 10:33
This post has helped me a lot of times. (I keep forgetting ;) )

12 Nov 2011, 00:57
Thanks so much! this should be in the manual :)