Ante is a very simple to use template engine. Please read The Ante User Guide to prepare for this page.
First requirement is having PHP 5.
To install Ante, get the latest version of the Ante tarball (link in the blue menu at the top left) and store it in a subfolder of your work directory (inside your web folders).
tar xzf Ante-Aug22.tgzthen you can include it in your PHP code.
Make sure that in any directory that you have a template, you create a directory antecache that is writable by your web server.
You can test that it works on your system by pointing your browser at ..../tests/testthem.php after creating the antecache directory ..../tests/antecache/ and making sure it's writable by your web server. That should show a green bar saying that 25 of 25 tests have passed and how long it took. If it reports something else. Please email me with a bug report. BTW, reloading the page should seriously reduce the time reported since the .php files created from the templates are already created.
I use PHP 5.2.0 as my development environment if you're interested in just getting it working. I've also tested from time to time in a PHP 5.0 environment.
The simplest way to use Ante from PHP is
$datasource is an AwDataSource object,
ANTEPATH is the folder where Ante is installed.
An AwDataSource is an interface with one method in it.
This method finds the objects that are set into the template.
The object returned must be an AwObject class (see next section).
It may also be a AwDataSource, in which case, depending on the template
it may be treated as an inner namespace to the current one.
If the name does not exist in this datasource, the datasource may
return null (to allow for chaining to the outer namespace) or false
(do not look in outer namespace/datasource).
To support the implicit loops, the
get method will be
called with the integers, starting with the number 1 and increasing
until the AwDataSource returns false.
AwObject is an interface with has three methods.
function getText(); returns the text that will be placed
inside tags as the text of the element (or the value attribute in a
input type="text" element)
function getInputName(); is a method that returns a
string that is placed in the name attribute of an
textarea or select
function getType(); returns
an AwInputType object that has such things as the value that is placed
in the type attribute of an
where the input type is not already set to one of checkbox, file,
radio, submit, button, file, image, or hidden.
The AwInputType object is an "advanced" section that I've implemented but haven't properly tested. More below.
AbstractAwObject is an abstract class to help the implementation of
AwObjects. Of the above, it implements
getInputName() (return the field awname) and
getType() which always returns an AwSimpleInputType object.
SimpleAwObject is a class that inherits from AbstractAwObject
and implements the
getText() method. It's constructor
awname field so that
in AbstractAwObject has something to return.
AwArrayDataSource is a useful class for treating an array as a datasource. It implements AwDataSource by treating each key in the array (or integer index) as an awname and returning a SimpleAwObject. (It also extends SimpleAwObject so that namespaces can also be objects).
Here's a sample of how to use it.
$datasource = new AwArrayDataSource( array(
'address' => '17 Avondale Crescent',
'city' => 'Kingston',
'province' => 'Ontario',
'children' => array(3, 'Bob', 'Margret', 'Jill')));
The following names would be valid in the template:
If the template writer wrote
<span class="aw_children">4</span>, the 4 would
be replaced with the first element in the 'children' array (3). (This
is why AwArrayDataSource extends SimpleAwObject.)
If you don't care about namespaces, you can use this class for things
(I'm using the Adodb package to interface to my database.) Assuming
that db.html is a template that uses the column names of the table
menutitles, we've done all the programming necessary to display
the menu titles. Ante looks after filling in the data correctly.
$adb = ADONewConnection($connectionstring);
$menunum = 1;
if (isset($_REQUEST['menunum'])) $menunum = $_REQUEST['menunum'];
$sql = 'select * from menutitles where menunum = ?';
$res = $adb->Execute($sql, array($menunum));
$datasource = new AwArrayDataSource($res->fields );
Now that you've finished all the interesting interface to Ante, please look through the Cookbook which shows how to create data for the templates in the User Guide.
function getInputType() must return a string that Ante
can place into the type attribute of input
getRequired are the
remaining methods on AwInputType. They are
mainly of use to add attributes to input methods. The attributes are
in the current
spec. They can be used to constrain what the browser will return to
the server (when browsers start supporting HTML5)
disabled attribute is supposed to disallow
the use of the input. The
required attribute is supposed
to tell the browser that the field must be filled in for the form to be
attributes are for numeric inputs.
maxLength attribute puts a limit on the length of
the string returned in the input, while the
attribute is supposed to be a regular expression describing what may
be submitted in the form.
accept attribute is actually in the HTML4 spec,
to specify what file types are accepted, but neither Firefox nor IE
yet support it properly.