PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Martin Barker   Funcational Template Manager   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: This contains 7 examples of how to load the class
Class: Funcational Template Manager
Template engine that replaces variables in files
Author: By
Last change: Updated to show new functions
Date: 14 years ago
Size: 3,978 bytes
 

Contents

Class file image Download
<?php
/******************************************************
** loads a Template and changes %OUT% to passesVars['OTU']
** or arrays %OUT.hello% passesVars['OUT']['hello']
** to unlimited depth
******************************************************/
include("template.php");
/******************************************************
** Example 1
******************************************************/
$tpl = new template();

$tpl->setName("test"); //sets path to templates/test/
$tpl->setFile("test"); //provides test.tpl inside path

$output = array('OUT' => 'this is an output', "array" => array("Martin", "Barker"));

$tpl->passVars($output); // passes an array of data to the template for replace
$tpl->passVar('OUT', 'this is an output'); // this will over right the other out as it uses array merge

echo $tpl->render(); // renders the output

/******************************************************
** Example 2
******************************************************/
$tpl = new template();

$tpl->setFile("test"); //provides test.tpl inside path

$output = array('OUT' => 'this is an output', "array" => array("Martin", "Barker"));

$tpl->passVars($output); // passes an array of data to the template for replace
$tpl->passVar('OUT', 'this is an output'); // this will over right the other out as it uses array merge

echo $tpl->render(); // renders the output

// please notice this dose not have $tpl->setName("test"); this will then use templates/default/

/******************************************************
** Example 3
******************************************************/
$tpl = new template();

$output = array('OUT' => 'this is an output', "array" => array("Martin", "Barker"));
                                                              
$tpl->setName("test"); //provides file path as templates/test

$tpl->passVars($output); // passes an array of data to the template for replace
$tpl->passVar('OUT', 'this is an output'); // this will over right the other out as it uses array merge

echo $tpl->render(); // renders the output

// Please notice this dose not have $tpl->setFile("test"); this will then use the default index.tpl

/******************************************************
** Example 4
******************************************************/
$tpl = new template();

$tpl->setName("test"); //sets path to templates/test/
$tpl->setFile("test"); //provides test.tpl inside path

echo $tpl.render(); // renders the output
// Please Notice There is not $tpl.passVars($output); or $tpl->passVar('OUT', 'this is an output');
// this will then cause the class to use $GLOBALS for the array

/******************************************************
** Example 5
******************************************************/
$tpl = new template("test", "test"); //sets path to templates/test/, provides test.tpl inside path

$output = array('OUT' => 'this is an output', "array" => array("Martin", "Barker"));

$tpl->passVars($output); // passes an array of data to the template for replace
$tpl->passVar('OUT', 'this is an output'); // this will over right the other out as it uses array merge

echo $tpl->render(); // renders the output


/******************************************************
** Example 6
******************************************************/
$output = array('OUT' => 'this is an output', "array" => array("Martin", "Barker"));
$tpl = new template("test", "test", $output); //sets path to templates/test/, provides test.tpl inside path

echo $tpl->render(); // renders the output

/******************************************************
** Example 7
******************************************************/
$output = array('OUT' => 'this is an output', "array" => array("Martin", "Barker"));

echo
$tpl = new template("test", "test", $output, $true); //sets path to templates/test/, provides test.tpl inside path and returns the source to output
?>