Search code examples
phphtmlloopstemplatingphpbb

PHPBB nested template loops not working correctly


I'm trying to wrap my head around PHPBB templating but it's not working like I want.

So this is what the HTML of my template looks like:

<div id="invtabs">
                  <ul>
                   <!-- BEGIN TAB_LOOP -->
                        <li><a href="#invtabs-{TAB_LOOP.TAB_ID}">{TAB_LOOP.TAB_NAME}</a></li>
                    <!-- END TAB_LOOP -->
                </ul>
                <!-- BEGIN TAB_LOOP -->
                <div id="invtabs-{TAB_LOOP.TAB_ID}">
                     <!-- BEGIN ITEM_LOOP -->
                        <img src ="images/custom_avatars/item_thumbnails/{TAB_LOOP.ITEM_LOOP.ITEM_ID}.png" />
                     <!-- END ITEM_LOOP -->
                </div>
                  <!-- END TAB_LOOP -->
            </div>

As you can see, I have a nested loop in the HTML and I'm trying to have

<img src ="images/custom_avatars/item_thumbnails/{TAB_LOOP.ITEM_LOOP.ITEM_ID}.png" />

show up in the content () of each tab, however the result I'm getting is each tab blank and the content (img) only showing up under the 8th tab. "hair" here's a picture to demonstrate.

enter image description here

This is the relevant PHP.

 //SEND TAB-INFO TO TEMPLATE AND BUILD TABS.
foreach($avatar_layer_tabs as $tabs){
    $template->assign_block_vars('TAB_LOOP', array(
        'TAB_ID' => $tabs['tab_id'],
        'TAB_NAME' => $tabs['tab_name']
        ));
}

//LOOP THROUGH ITEMS -> CHECK FOR THUMBAIL
    foreach($users_items as $items){
        $template->assign_block_vars('TAB_LOOP.ITEM_LOOP', array(
            'ITEM_ID' => $items['item_id'],
            'ITEM_TAB' => $items['main_tab']
            ));
    }

Solution

  • So I've found the answer. It was a silly mistake in my logic.

    foreach($avatar_layer_tabs as $tabs){
        $template->assign_block_vars('TAB_LOOP', array(
            'TAB_ID' => $tabs['tab_id'],
            'TAB_NAME' => $tabs['tab_name']
            ));
    
        if($users_items){
    
        //LOOP THROUGH ITEMS -> CHECK FOR THUMBAIL
            foreach($users_items as $items){
                makeThumbnails();
                $template->assign_block_vars('TAB_LOOP.ITEM_LOOP', array(
                    'ITEM_ID' => $items['item_id'],
                    'ITEM_TAB' => $items['main_tab']
                    ));
            }
        } else {
            trigger_error('There was a problem, it looks like you have no items. Please contact an administrator.');
        }
    }
    

    I had the "item_loop" outside the "tab_loop" rather than inside, which made the item_loop attach to the last iteration of the tab_loop.