PHP Classes
elePHPant
Icontem

File: template.example.php

Recommend this page to a friend!
  Classes of Matthew Knowlton  >  ExTemplate  >  template.example.php  >  Download  
File: template.example.php
Role: Example script
Content type: text/plain
Description: Example PHP for proccessing a template
Class: ExTemplate
Extensible template engine with callable functions
Author: By
Last change:
Date: 4 years ago
Size: 1,416 bytes
 

 

Contents

Class file image Download
<?php

require_once('template.class.php');
require_once(
'template.commands.php');

session_start();

$template = new template('template.demo.php');


addTemplateCommands($template);

$template->add_command('includeStyles', function ($params) use ($template){
    return
'<link rel="stylesheet" type="text/css" href="'.$params[0].'"/>'."\r\n";
});

$template->add_command('includeScript', function ($params) use ($template){
    return
'<script type="text/javascript" src="'.$params[0].'"></script>';
});


$template->set_macros(array(
   
'HeaderFile' => 'demo.header.php',
   
'FooterFile' => 'demo.footer.php',
   
'ScriptsFile' => 'demo.scripts.js',
   
'StylesFile' => 'demo.styles.css',
   
'PageTitle' => 'Benefits of using a Templating Engine',
   
'BenefitsOfTemplates' => array(
       
'Abstraction between Code & Output',
       
'Simplification of Output Handling',
       
'Sandboxing User Created Layouts',
       
'Easier for Non-programmmers to Write/Read',
       
'Easy data handoff between Front-End & Back-End Developers',
       
'Simple data escaping implementation'
   
)
));


$template->add_macro('isLoggedIn', (bool)(isset($_SESSION['UserName'])));
$template->add_macro('signInLink', 'demo.signin.php');

if(isset(
$_SESSION['UserName'])){
   
$template->add_macro('UserName', $_SESSION['UserName']);
}

echo
$template->render();

exit();

?>