7. Working with BEGINBLOCK

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?

More Comments/Post Your Own

Advertisement

Online Users

There are 86 users online.

Connect

Connect with us on Facebook

Newsletter

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