vLIB Einführung |
![]() |
Oft wird die HTML-Ausgabe nach verschiedenen Zuständen entschieden. Ist der User ein Administrator oder ein einfacher Benutzer beispielsweise. Oder wenn eine bestimmte Variable gesetzt ist, muss ein bestimmtes Wort in roter Farbe geschrieben werden.
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();
(...)
<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>