Main Menu

· Home
· Benchmarks
· Documentation
· Download
· License
· Thanks

Main Documentation

Contents

Installation & Configuration

Installation of bTemplate should be easy. Simply drop the class definition (bTemplate.php) into a directory and include it in your script.

bTemplate has a variety of different configuration options which are described below.

$base_path
The base path is the directory your templates will go in. Please note that all templates must reside in this directory (or sub-directories of this directory). Please be sure to make it an absolute path, or you can run into confusion later. You can set this in the variable, or simply pass a single argument to the constructor and it will be set automatically. If you use the constructor to set the base path, please be aware that you can use multiple bTemplate objects to access templates from different base directories.

$reset_vars
This variable (TRUE or FALSE) determines whether to reset the $loop and $cloop arrays after a fetch() call. You can pass it as the second argument in a constructor as well.

$ldelim and $rdelim
These variables set the start and end tags between which you will place your tags. For example, if you change them to { and }, you will write your templates with tags such as {tag:title}.

$BAldelim and $BArdelim
BA stands for "begin array" and these variables set the delimiters for opening loop tags. For example, if you change them to { and }, you will write your templates with tags such as {loop:array}.

$EAldelim and $EArdelim
EA stands for "end array" and these variables set the delimiters for closing loop tags. For example, if you change them to {/ and }, you will write your templates with tags such as {/loop:array}. Please note that you must provide some way for the script to distinguish between start and end tags! If you do not, the script will get confused.

Public Methods

Public methods are those which the programmer calls explicitly.

bTemplate()
This is the constructor, a function which gets called automatically when a bTemplate object is created. It can take a single argument, the base path where your templates are located. If you do not set the path in the bTemplate.php file and you do not pass a valid path to the constructor, you will get "unable to open file" errors. It can also take two arguments, the first being the base path (set it to NULL if you don't need to set it but need to pass the second argument) and the second being TRUE or FALSE. The TRUE or FALSE determines whether bTemplate resets the $loop and $cloop arrays after a fetch() call.

set()
The set method allows you to assign variables to the template object. These variables can then be referenced using the template syntax described elsewhere. The set method takes two arguments, the name of the tag you're assigning and the variable you are assigning to it. The variable can be a scalar or an array, it makes no difference. This method can also take an optional third parameter (TRUE) if you want bTemplate to look for matching "if" statements in the template.

set_cloop()
This method sets a "case loop" and takes three arguments. Please see the intro section for more information.

fetch()
The fetch method opens the specified template file, parses it, and returns the parsed template as a string. You can then do whatever you wish with this string (assign it to another template variable, print it to the user, etc.). The fetch method takes a single argument, the name of the template you wish to parse.

reset_vars()This method allows you to manually reset any of the template variables. This is useful if you are using multiple template files and you have already parsed an "inner" template and don't require the outer template to parse some of the variables. It takes four arguments, each of them being TRUE or FALSE. Set a true if you want the corrosponding variables to be reset, or a false if not. It's in this order: scalars, arrays, carrays, ifs.

Private Methods

A list of private methods and what they do is no longer available in the documentation. If you need to look at the private methods, please see the comments in the source code.