[SOLVED] Nested Block Variables/Templating Question

Discussion of general topics related to the new version and its place in the world. Don't discuss new features, report bugs, ask for support, et cetera. Don't use this to spam for other boards or attack those boards!
Forum rules
Discussion of general topics related to the new release and its place in the world. Don't discuss new features, report bugs, ask for support, et cetera. Don't use this to spam for other boards or attack those boards!
Post Reply
texasaggie
Registered User
Posts: 2
Joined: Mon May 05, 2008 2:43 am

[SOLVED] Nested Block Variables/Templating Question

Post by texasaggie »

Not really sure this is a support question but more a general "how to" type question for 3.x.

I have a template that I need to have nested values in. The documentation seems to cover this well but only from the template side.

Here's a simplified version of the template:

Code: Select all

<!-- BEGIN outer_loop --> 
  << do some markup>>
    <!-- BEGIN inner_loop --> 
      << do some markup>>
    <!-- END inner_loop --> 
  << do some markup>>
<!-- END outer_loop --> 

The question is, I'm unclear how the PHP side of this should look and I can't figure it out (have tried numerous things). What is throwing me is how to assign the template variables for the nested inner loop. Should I be assigning the vars to an array within the first array and then only assigning block variables just to the outside? I also thought you might be able to qualify/name the inner using a "outer_loop.inner_loop" convention, but that didn't do it either.

For example:

Code: Select all


<<start outer PHP looping construct>>

  $array1['a'] = 'foo';
  $array1['b'] = 'bar'l
  $template->assign_block_vars('outer_loop', $array1);

  << start inner PHP looping construct >>

    $array2 = array();
    $array2['c'] = 'oof';
    $array2['d'] = 'rab';

    // Should this be:

    $template->assign_block_vars('inner_loop', $array2);
    
    // or

   $template->assign_block_vars('outer_loop.inner_loop', $array2);
 
    // or

    $array1['innerloop'] = $array2;

   // or ????

  << end inner PHP looping construct >>

<< end outer PHP loop>>

Last edited by texasaggie on Mon May 05, 2008 4:29 am, edited 1 time in total.

User avatar
Prince of area51
Registered User
Posts: 133
Joined: Mon Jun 27, 2005 8:46 pm
Location: Manchester, UK
Contact:

Re: Nested Block Variables/Templating Question

Post by Prince of area51 »

This example might be useful:
On [url=http://olympuswiki.naderman.de/]Olympus Wiki[/url] » [url=http://olympuswiki.naderman.de/Template_Syntax]Template Syntax[/url] » [url=http://olympuswiki.naderman.de/Template_Syntax#Blocks]Blocks[/url] someone wrote:

Code: Select all

while($topic = $db->sql_fetchrow($result))
{
    $template->assign_block_vars('topic', array('TOPIC_ID' => $topic['topic_id']));

    while($post = $db->sql_fetchrow($result))
    {
        $template->assign_block_vars('topic.post', array('POST_ID' => $post['post_id']));
    }
}
For more information: Template Syntax - Blocks

texasaggie
Registered User
Posts: 2
Joined: Mon May 05, 2008 2:43 am

Re: Nested Block Variables/Templating Question

Post by texasaggie »

Thanks! I would swear that I tried that already, but I've tried so many different variations, perhaps I did not get that one quite right. Thanks for the link as well as I had not come across that one yet.


** UPDATE: That fixed it. Thanks!

aLiEnTxC
Registered User
Posts: 1
Joined: Fri Nov 14, 2008 9:20 am

Re: [SOLVED] Nested Block Variables/Templating Question

Post by aLiEnTxC »

Hi..

can it be, that this function not support more than one nested blocks?

I tried the follow and get only "Parse error: syntax error, unexpected '=' in /path/includes/template.php(175) : eval()'d code on line 94"

Code: Select all

 while ($row = $db->sql_fetchrow($result))
    {
      $template->assign_block_vars('block1.block2', array(XXXX));
      if ($list_type == TYPE_AGENTS)
      {
        $agents_ary = get_agents_ary($row['a_id']);
        foreach ($agents_ary as $row_a)
        {
          $template->assign_block_vars('block1.block2.agent_row', get_agent_template_ary($row_a));
        }
      }
    }

Code: Select all

<!-- BEGIN block1 -->
  <!-- BEGIN block2 -->
    <!-- BEGIN agent_row -->
    <!-- END agent_row -->
  <!-- END block2 -->
<!-- END block1 --> 
EDIT:
sorry.. it works.. i made a mistake while i used <!-- BEGIN block1.block2.agent_row --> and not like i said it above.. now it works :-)

Post Reply