PDA

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


rossco_2005
12-12-2009, 04:35 PM
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
05-02-2010, 09:47 PM
THank ya.

I thought it was dot syntax, too, heh.

Anyone know why it's not?

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

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

arvid
06-16-2011, 08:33 AM
This post has helped me a lot of times. (I keep forgetting ;) )

LuisMontemayor
11-11-2011, 11:57 PM
Thanks so much! this should be in the manual :)