6. Working with BEGINIF

BEGINIF is useful if you need a template to be adaptive to special conditions. For example if the user is logged in should display some information.


<!-- BEGINIF expr --><!-- ENDIF -->
<!-- BEGINIF expr --><!-- ELSE --><!-- ENDIF -->

expr can be any SIMPLE expression, such as $login (true or false), $user_level > 3: eg:

<!-- BEGINIF $user_level > 3 -->You are user level > 3<!-- ENDIF -->


In test.tpl:

<!-- BEGINIF $login -->
You are logged in!
<!-- ELSE -->
You are not logged in!
<!-- ENDIF -->

In test.php:

require './includes/user_init.php';

// since this is just a sample, we override the real login value
$login = true;

$txt['main_body'] = quick_tpl (load_tpl ('test.tpl'), $txt);
flush_tpl ();

Play with $login variable to see the result.



There is no comment. Why not be the first?

More Comments/Post Your Own