print

7b. Working with BEGINBLOCK / SUBBLOCK

You are here: C97net3. Developer's Guide

How to use BEGINBLOCK/SUBBLOCK with tpl

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?

read more More Comments/Post Your Own

Account

Search

Tags

acp add all also any create default display don download easy echo etc features field file files folder form function includes information init kemana link list may module name need number own page php please qengine read require script set site skin time tpl url use user using version welcome