This is a collection of PHP code to show how to set up for the Ante templates in the User Guide.
This is a simple example, so simple code will suffice.
Assuming that the template is in the file antesol.html, the following
code will produce:
<?php
require_once ANTEPATH.'Ante.inc';
$datasource = new AwArrayDataSource( array(
'title' => 'My title',
'body' => 'My Body'
));
Ante::render('antesol.html', $datasource);
?>
This will produce:
<html>
<head>
<title class="aw_title">My title</title>
</head>
<body class="aw_body">My Body</body>
</html>
This will require some more interesting code.
<?php
require_once ANTEPATH.'Ante.inc';
$loggedin = !empty($_SESSION['loginname']);
if ($loggedin){
$datasource = new AwArrayDataSource( array(
'body' => 'This will become the body text for people who have logged in.'
));
} else {
$datasource = new AwArrayDataSource( array(
'notloggedin' => 'not logged in',
'body' => 'This will become the body text for people who have not logged in.'
));
}
Ante::render('conditions.html', $datasource);
?>
This time we're using the PHP superglobal $_SESSION, and assume that if $_SESSION['loginname'] is not empty that the person is logged in. Then we create a datasource, depending on whether the person is logged in. If 'notloggedin' is not set, is null or false the contents of the div with class aw_notloggedin will not show.
Again we're going to use a simple AwArrayDataSource.
<?php
require_once ANTEPATH.'Ante.inc';
$datasource = new AwArrayDataSource( array(
'name' => 'Joan',
'gender' => 'female'
));
Ante::render('special.html', $datasource);
?>
Array Data Source makes doing namespaces easy.
<?php
require_once ANTEPATH.'Ante.inc';
$datasource = new AwArrayDataSource( array(
'name' => 'Joan',
'boss' => array(
'name' => 'Bob'
)
));
Ante::render('names.html', $datasource);
?>
It also makes loops easy.
<?php
require_once ANTEPATH.'Ante.inc';
$datasource = new AwArrayDataSource( array(
'name' => 'Dan',
'employee' => array(
'hidden', /* this is the 0, Ante arrays are 1 based */
array( 'name' => 'David'),
array( 'name' => 'Albert'),
array( 'name' => 'Joanne')
)
));
Ante::render('loops.html', $datasource);
?>
And simpler loops are even easier.
<?php
require_once ANTEPATH.'Ante.inc';
$datasource = new AwArrayDataSource( array(
'fruit' => array(
'hidden',
'Oranges',
'Grapefruit',
'Lime',
'Lemon
)
));
Ante::render('loops2.html', $datasource);
?>
If your team decides for included templates such as used in the
first sample bit in the userguide on Included Tempaltes,
what you do is tell Ante to include both templates.
<?php
require_once ANTEPATH.'Ante.inc';
$datasource = new AwArrayDataSource( array(
'title' => 'My title',
'body' => 'My Body'
));
Ante::render(array('inc1.html', 'inctemplate.html'), $datasource);
?>
This code assumes that there's a database table comments
with columns: title, username, timestamp, and text.
<?php
require_once '../../adodb5/adodb.inc.php';
require_once '../Ante.inc';
$adb = ADONewConnection($connectionstring);
$sql = 'select * from comments order by cid desc';
$res = $adb->Execute($sql);
$datasource = new AwArrayDataSource($res->fields );
Ante::render('comments.html', $datasource);
?>