PDA

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


rossco_2005
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_page_templates();
$templater->register('navbar', $navbar);
$templater->register('binaries', $binaries);
print_output($templater->render());


In my template I can use this code fine:


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


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}
</vb:each>
</vb:each>


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}
</vb:each>
</vb:each>

(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']}}

Sarteck
02 May 2010, 23:47
THank ya.

I thought it was dot syntax, too, heh.

Anyone know why it's not?

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

http://www.vbulletin.com/forum/project.php?issueid=37479

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

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