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).
Subscribe to our newsletter for the latest updates and exciting promotions!