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


Latest Comments

  • Guest on Forum
    “noFollow links.” - Jun 19
  • username on Forum
    “Sponsor or Premium user” - Jun 14
  • on Forum
    “Template https://www.website.com/skins/_common/section.tpl not found! contact webmaster” - Feb 24
  • admin on 01. Administration Panel
    “Untitled” - Jan 24
  • on 01. Administration Panel
    “Can't Login to Admin” - Jan 23

Most Commented

Online Users

There are 136 users online.


Connect with us on Facebook


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