Hyena Template Engine Usage Examples
========================================================================================
========================================================================================
Simple page design Example (using separate layout template elements):
========================================================================================
Template Direcotry:
===================
->header.php
->nav.php
->body.php
->footer.php
===================
index.php:
<?php
require_once "includes/configure.php";
require_once "includes/classes/template.class.php";
$template = new TemplateEngine(CSS,TEMPLATE,INCLUDES,URL,JS,PAGE,$mysql);
$css = $template->load("hyena-layout.css","css");
$template->printopen($css,"Your Page Title Here");
$template->load("header.php","template");
$template->load("nav.php","template");
$template->load("body.php","template");
$template->load("footer.php","template");
$template->printclose();
?>
========================================================================================
Simple page design Example (full page using only template tags):
========================================================================================
Template Direcotry:
===================
->index.php
===================
index.php:
<?php
require_once "includes/configure.php";
require_once "includes/classes/template.class.php";
$template = new TemplateEngine(CSS,TEMPLATE,INCLUDES,URL,JS,PAGE,$mysql);
$css = $template->load("hyena-layout.css","css");
$template->load("index.php","template");
?>
=======================================================================================
Template Example(with template tags):
=======================================================================================
Template Directory:
===================
->template_example.php
===================
Page Direcotry (after compiling):
=================================
->template_example.php
=================================
template_example.php (in template directory):
<div id="example">
The time this template was compiled was at: <--DATE-->
</div>
when compiled becomes for example:
template_example.php (in page directory after compiling):
<div id="example">
The time this template was compiled was at: February 5, 2007 14:58:26
</div>
======================================================================================
Template Example(with template tags and a database connection):
======================================================================================
Template Directory:
===================
->template_database_example.php
===================
Page Direcotry (after compiling):
=================================
->template_database_example.php
=================================
template_database_example.php (in template directory):
<div id="example">
Site Address: <--URL--><br><br>
<?php
/*
This will print out rows from the database
*/
$connection = mysql_connect('localhost','your-uid','your password');
mysql_select_db('your db',$connection);
$your_sql = "SELECT * FROM your_table";
$rs = mysql_query($your_sql,$connection) or die("Query failed");
while($rows = mysql_fetch_array($rs)) {
print $rows['f1']."<br>";
print $rows['f2']."<br>";
print $rows['f3']."<br>";
}
mysql_close();
?>
</div>
when compiled becomes for example:
template_databasde_example.php (in page directory after compiling):
<div id="example">
Site Address: http://www.yoursite.com<br><br>
<?php
/*
This will print out rows from the database. Don't worry
the php code executes normally
*/
$connection = mysql_connect('localhost','your-uid','your password');
mysql_select_db('your db',$connection);
$your_sql = "SELECT * FROM your_table";
$rs = mysql_query($your_sql,$connection) or die("Query failed");
while($rows = mysql_fetch_array($rs)) {
print $rows['f1']."<br>";
print $rows['f2']."<br>";
print $rows['f3']."<br>";
}
mysql_close();
?>
</div>
|