VlibTemplate

From Wikipedia, the free encyclopedia
Jump to: navigation, search
vlibTemplate
Stable release
4.1.0
Type Template Engine
Website http://vlib.clausvb.de/

vlibTemplate is a template engine written in PHP. Programmers and web developers may use it for web development. vlibTemplate is a PHP class that is intended to make splitting PHP from HTML a simple and natural task, using markup tags. This class allows users to set values for variables, loops, if statements, etc. which are declared in the template.

vlibTemplate is a part of vLIB. It has an interface to vlibDate and vlibMimeMail.

Code example[edit]

Since vlibTemplate separates PHP from HTML, there are two files:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
   <title>{tmpl_var name='title_text'}</title>
   <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
</head>

<body>

<p>{tmpl_var name='body_text'}</p>
<div>{tmpl_var name='div_cont'}</div>

</body>
</html>

Note that this file contains plain HTML and one markup tag. TMPL_VAR is used to display template variables, which are assigned in the PHP script:

require_once 'vlib/vlibTemplate.php';

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

$tmpl->setvar('title_text', 'TITLE: This is the vLIB basic example ...');
$tmpl->setvar('body_text', 'BODY: This is the message set using setvar()');
$tmpl->setvar('div_cont' , 'DIV : This is div paragraph');
$tmpl->pparse();

Using the vlibTemplateCache can speed up the parsing process.

Features[edit]

  • WYSIWYG: you can design and edit your templates with Frontpage, Dreamweaver or any other WYSIWYG HTML editor you can think of.
  • Structure and Modularity: vlibTemplate will help you a great deal about modularity and structure of your code. It will help you to create cleaner code, too.
  • Template includes: you can include a template file from within another template file so, for example, you can have a site footer that you point to from each template, if you needed to change the footer, it can be done simply by editing 1 file.
  • Template loops: you can set up loops in your template for maybe showing the result of a database query. You can use setdbloop and let handle vlibTemplate the $result (e.g. returned by mysql_query, pg_query or ora_do). vlibTemplate can handle a lot of RDBMS like: MySQL, PostgreSQL, Oracle, Informix and others.
  • Template conditions: you can actually use boolean conditions in your template (<tmpl_if name="is_true"></tmpl_if>), this can be handy for displaying different color in a table, or showing a list of results in a search page.
  • Template caching: you can cache your templates to a file which means that vlibTemplate reads the template from the cache (which is already compiled) and thus can save much time while writing a page.
  • Template debugging: if you want to see exactly what's being used by vlibTemplate you can see by using vlibTemplateDebug. This class will output an HTML-formatted page with all data needed to see where you're going wrong. It will even tell you if there are errors in the way you've written the template.

External links[edit]