VlibTemplate
Encyclopedia
vlibTemplate is a template engine
written in PHP
. Programmer
s and web developer
s 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. It makes use of the following vlibTemplate markup tags (like html tags); {tmpl_var}, {tmpl_loop} and so on.
The file written with these style tags is called a template. A template can be an HTML
file to use on the web, or perhaps a text file to use as an e-mail template... as you can guess there are many possibilities. The template file is always separate from the PHP script that uses it, that way, a designer for example can change the template file without having to go through all of the php coding, thus saving the developer having to worry about it.
Using this class you set the values for the variables, loops, if statements, etc. which are declared in the template. This enables you to separate all of the design from the data, which you create using PHP.
vlibTemplate is a part of vLIB. It has an interface
to vlibDate and vlibMimeMail. You can program powerful web application
s with vLIB.
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:
Even complicated designs can be programmed with vlibTemplate. You can use vlibTemplateCache to speed up the parsing process.
Template engine
A template engine is software that is designed to process web templates and content information to produce output web documents. It runs in the context of a template system.-Types:...
written in PHP
PHP
PHP is a general-purpose server-side scripting language originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document...
. Programmer
Programmer
A programmer, computer programmer or coder is someone who writes computer software. The term computer programmer can refer to a specialist in one area of computer programming or to a generalist who writes code for many kinds of software. One who practices or professes a formal approach to...
s and web developer
Web developer
A web developer is a software developer or software engineer who specializes in, or is specifically engaged in, the development of World Wide Web applications, or distributed network applications that are run over HTTP from a web server to a web browser....
s may use it for web development
Web development
Web development is a broad term for the work involved in developing a web site for the Internet or an intranet . This can include web design, web content development, client liaison, client-side/server-side scripting, web server and network security configuration, and e-commerce development...
. vlibTemplate is a PHP class
Class (computer science)
In object-oriented programming, a class is a construct that is used as a blueprint to create instances of itself – referred to as class instances, class objects, instance objects or simply objects. A class defines constituent members which enable these class instances to have state and behavior...
that is intended to make splitting PHP from HTML a simple and natural task. It makes use of the following vlibTemplate markup tags (like html tags); {tmpl_var}, {tmpl_loop} and so on.
The file written with these style tags is called a template. A template can be an HTML
HTML
HyperText Markup Language is the predominant markup language for web pages. HTML elements are the basic building-blocks of webpages....
file to use on the web, or perhaps a text file to use as an e-mail template... as you can guess there are many possibilities. The template file is always separate from the PHP script that uses it, that way, a designer for example can change the template file without having to go through all of the php coding, thus saving the developer having to worry about it.
Using this class you set the values for the variables, loops, if statements, etc. which are declared in the template. This enables you to separate all of the design from the data, which you create using PHP.
vlibTemplate is a part of vLIB. It has an interface
Interface (computer science)
In the field of computer science, an interface is a tool and concept that refers to a point of interaction between components, and is applicable at the level of both hardware and software...
to vlibDate and vlibMimeMail. You can program powerful web application
Web application
A web application is an application that is accessed over a network such as the Internet or an intranet. The term may also mean a computer software application that is coded in a browser-supported language and reliant on a common web browser to render the application executable.Web applications are...
s with vLIB.
Code example
Since vlibTemplate separates PHP from HTML, you have two files:
{tmpl_var name='title_text'}
{tmpl_var name='body_text'}
Note that this file contains plain HTML
HTML
HyperText Markup Language is the predominant markup language for web pages. HTML elements are the basic building-blocks of webpages....
and one markup tag. TMPL_VAR is used to display template variables, which are assigned in the PHP
PHP
PHP is a general-purpose server-side scripting language originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document...
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->pparse;
Even complicated designs can be programmed with vlibTemplate. You can use vlibTemplateCache to speed up the parsing process.
Features
- WYSIWYGWYSIWYGWYSIWYG is an acronym for What You See Is What You Get. The term is used in computing to describe a system in which content displayed onscreen during editing appears in a form closely corresponding to its appearance when printed or displayed as a finished product...
: you can design and edit your templates with FrontpageMicrosoft FrontPageMicrosoft FrontPage was a WYSIWYG HTML editor and web site administration tool from Microsoft for the Microsoft Windows line of operating systems. It was branded as part of the Microsoft Office suite from 1997 to 2003...
, Dreamweaver or any other WYSIWYGWYSIWYGWYSIWYG is an acronym for What You See Is What You Get. The term is used in computing to describe a system in which content displayed onscreen during editing appears in a form closely corresponding to its appearance when printed or displayed as a finished product...
HTML editorHTML editorAn HTML editor is a software application for creating web pages. Although the HTML markup of a web page can be written with any text editor, specialized HTML editors can offer convenience and added functionality. For example, many HTML editors work not only with HTML, but also with related...
you can think of. - Structure and ModularityModularity (programming)Modular programming is a software design technique that increases the extent to which software is composed of separate, interchangeable components called modules by breaking down program functions into modules, each of which accomplishes one function and contains everything necessary to accomplish...
: 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: MySQLMySQLMySQL officially, but also commonly "My Sequel") is a relational database management system that runs as a server providing multi-user access to a number of databases. It is named after developer Michael Widenius' daughter, My...
, PostgreSQLPostgreSQLPostgreSQL, often simply Postgres, is an object-relational database management system available for many platforms including Linux, FreeBSD, Solaris, MS Windows and Mac OS X. It is released under the PostgreSQL License, which is an MIT-style license, and is thus free and open source software...
, OracleOracle databaseThe Oracle Database is an object-relational database management system produced and marketed by Oracle Corporation....
, InformixInformixIBM Informix is a family of relational database management system developed by IBM. It is positioned as IBM's flagship data server for online transaction processing as well as integrated solutions...
and others. - Template conditions: you can actually use boolean conditions in your template (
), 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.