7b. Working with BEGINBLOCK / SUBBLOCK

You can also create a block inside another block. Currently qE only supports 2 level block, by using BEGINBLOCK/SUBLOCK.

Usage

<!-- BEGINBLOCK blockname -->
HTML CODE
<!-- BEGINSUBBLOCK blockname -->HTML CODE<!-- ENDSUBBLOCK -->
HTML CODE
<!-- ENDBLOCK -->

Sample

test.tpl

<p>Welcome to test page!</p>

<table border="1">
<tr>
<!-- BEGINBLOCK list -->
<td>
<table border="1">
<tr><th>#</th><th>Title</th></tr>
<!-- BEGINSUBBLOCK list -->
<tr><td>{$j}-{$i}</td><td>{$title}</td></tr>
<!-- ENDSUBBLOCK -->
</table>
</td>
<!-- ENDBLOCK -->
</tr>
</table>

test.php

<?php
require './includes/user_init.php';

// now load the output tpl
$tpl = load_tpl ('test.tpl');

// all block output must be contained in $var['block_list']
$txt['block_list'] = '';

// create the sample
for ($j = 1; $j < 4; $j++)
{
// don't forget to ALWAYS initialize the sub-container
$txt['subblock_list'] = '';
for ($i = 1; $i < 10; $i++)
{
$row = array ();
$row['j'] = $j;
$row['i'] = $i;
$row['title'] = random_str (16);

// build the subblock (inner block), by quick_tpl-ing
// the $tpl_subblock['list']
$txt['subblock_list'] .= quick_tpl ($tpl_subblock['list'], $row);
}

// and build the outer block, by quick_tpl-ing the $tpl_block['list']
$txt['block_list'] .= quick_tpl ($tpl_block['list'], $txt);
}

// output
$txt['main_body'] = quick_tpl ($tpl, $txt);
flush_tpl ();
?>

Explanation

So creating a BLOCK/SUBBLOCK is actually quite easy. First create the subblock (inner block) by quick_tpl-ing $tpl_subblock. Then finally, quick_tpl the $tpl_block.


There is no comment. Why not be the first?

More Comments/Post Your Own

Advertisement

Online Users

There are 120 users online.

Connect

Connect with us on Facebook

Newsletter

Subscribe to our newsletter for the latest updates and exciting promotions!