vlibTemplate

vLib Logo

4.2. TMPL_IF
PHP script
   require_once 'vlib/vlibTemplate.php';

   $tmpl = new vlibTemplate('tmpl/tmpl_if.htm');

   $boolean = (isset($_GET['if_condition'])) ? 1 : 0;

   $tmpl->setvar('boolean', $boolean);
   $tmpl->setvar('if_condition', $_GET['if_condition']);

   $tmpl->pparse();
Template
   (...)
         <style type="text/css">
         body
         { 
            font-family: Arial;
            font-size: 0.9em;
            color: <tmpl_if name='boolean'>purple<tmpl_else>gray</tmpl_if>;
         }
         pre { color: black; font-size: 1.1em; }
      </style>
   </head>
   
   <body>
   
   <p>This text is gray without "if_condition" set. Click
   <a href="tmpl_if.php?if_condition=1">here</a> to make it purple. 
   <tmpl_if name='if_condition' op='>' value='5'><span 
   style="color: green">"if_condition" is more than 5.</span><tmpl_else>
   "if_condition" is not set or below (equal to) 5.</tmpl_if></p>