print

8b. Working with BEGINSECTION (2)

You are here: C97net3. Developer's Guide

How to use BEGINSECTION with tpl (part 2)

This part covers a more complex usage of BEGINSECTION.

As mentioned, you can use SECTION with BLOCK & IF, this is how you do that.

Code

In section.tpl:

<!-- BEGINSECTION justtest -->
<table border="1" width="100%">
<!-- BEGINIF $login -->
<tr><td style="background:green">Logged In</td></tr>
<!-- ELSE -->
<tr><td style="background:red">Not Logged</td></tr>
<!-- ENDIF -->
</table>
<!-- ENDSECTION -->

In test.tpl:

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

<h1>Test 1</h1>
{$table1}

<h1>Test 2</h1>
{$table2}

In test.php:

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

// load the required section (in section.tpl)
// usually you don't need this, as qE load section.tpl automatically
load_section ('section.tpl');

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

// then create the sample data
$login = false;
$txt['table1'] = quick_tpl (load_tpl ('var', $tpl_section['justtest']), $txt);

$login = true;
$txt['table2'] = quick_tpl (load_tpl ('var', $tpl_section['justtest']), $txt);

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

Explanation

The important part is:

$txt['table1'] = quick_tpl (load_tpl ('var', $tpl_section['justtest']), $txt);

You have already know load_tpl, now we have load_tpl ('var', var). load_tpl ('var', var) is used to load a template from a variable instead of a tpl file. So using the above line, qE loads template from $tpl_section['justtest'] variable, which is defined in section.tpl.

By loading the tpl from a variable, you can easily manipulate the output. In this example, you can use the same SECTION to display the result according to $login status (by using BEGINIF).


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