print

7. Working with BEGINBLOCK

You are here: C97net3. Developer's Guide

How to use BEGINBLOCK with tpl

BEGINBLOCK is used to display repeated output (loops).

Usage

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

Sample

test.tpl

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

<table border="1">
    <tr>
        <th>#</th><th>Title</th>
    </tr>
    <!-- BEGINBLOCK list -->
    <tr>
        <td>{$i}</td><td>{$title}</td>
    </tr>
    <!-- ENDBLOCK -->
</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_name']
$txt['block_list'] = '';

// create the sample
for ($i = 1; $i < 10; $i++)
{
    $row = array ();
    $row['i'] = $i;
    $row['title'] = random_str (16);
   
    // build the block, by quick_tpl-ing the $tpl_block['list']
    // $tpl_block defined automatically by load_tpl above
    $txt['block_list'] .= quick_tpl ($tpl_block['list'], $row);
}

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

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