vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   [TEMPLATE SYNTAX] vb:each from piece of an array (https://vborg.vbsupport.ru/showthread.php?t=230049)

rossco_2005 12-12-2009 04:35 PM

[TEMPLATE SYNTAX] vb:each from piece of an array
 
I have an array:

PHP Code:

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

I then render a template:

PHP Code:

$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:

HTML Code:

<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:

HTML Code:

<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:
Code:

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 [DATE]1260659509[/DATE] at [TIME]1260659509[/TIME] ---------------

I figured this out.
I must use this:
HTML Code:

<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 [DATE]1260659823[/DATE] at [TIME]1260659823[/TIME] ---------------

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

HTML Code:

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

Sarteck 05-02-2010 08:47 PM

THank ya.

I thought it was dot syntax, too, heh.

Anyone know why it's not?

Andreas 05-03-2010 02:53 AM

Quote:

Originally Posted by rossco_2005 (Post 1929385)
Or have I found a vBulletin bug?

Yes you did.

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

arvid 06-16-2011 07:33 AM

This post has helped me a lot of times. (I keep forgetting ;) )

LuisMontemayor 11-11-2011 10:57 PM

Thanks so much! this should be in the manual :)


All times are GMT. The time now is 07:16 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01454 seconds
  • Memory Usage 1,732KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (4)bbcode_html_printable
  • (2)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete