File: demo.php

Recommend this page to a friend!
  Classes of wim niemans  >  Sirenade PHP Template Compiler  >  demo.php  >  Download  
File: demo.php
Role: Example script
Content type: text/plain
Description: demo source
Class: Sirenade PHP Template Compiler
Compile templates to PHP and caches the results
Author: By
Last change: demo objects access added
Date: 2 months ago
Size: 3,360 bytes
 

Contents

Class file image Download
<?php
/**
 * This file is an example of an application with Templet class.
 * Distribution is intended for education / studying purposes only.
 *
 * Copyright [2021] [Wim Niemans <niemans@pbsolo.nl>]
 */

include '../Template.class.php';

/**
 * @author wim niemans, Rotterdam, Bonn
 * @license EUPL
 */

$template = new Template(); // default: keepOrphans

$template->setVar('speed', 'quick');
$template->setVar('color', 'brown');
$template->setVar('action', 'jumps');
$template->setVar('pet', 'dog');
$template->setVar('printMe', true); // variable used in logic features

clearstatcache();
$time = microtime(true);

$embeddedVars = '"The ".{speed}." ".{color}." fox ".{action}." over the lazy ".{pet}."."';
// unit test 1 php native
$template->setVar('pangram', "<?php echo $embeddedVars ".' ?'.'>');
$template->parse('output', 'pangram');
echo
'unit 1 ' . $template->tidy('output') . " \n";

// unit test 2 php echo native
$template->setVar('pangram', "<?= $embeddedVars".' ?'.'>');
$template->parse('output', 'pangram');
echo
'unit 2 ' . $template->tidy('output') . " \n";

// unit test 3 asp tags
$template->setVar('pangram', "<% echo $embeddedVars".' %>');
$template->parse('output', 'pangram');
echo
'unit 3 ' . $template->tidy('output') . " \n";

// unit test 4 asp echo's
$template->setVar('pangram', "<%= $embeddedVars".' %>');
$template->parse('output', 'pangram');
echo
'unit 4 ' . $template->tidy('output') . " \n";

// unit test 5 html comment
$template->setVar('pangram', '<!-- The {speed} {color} fox {action} over the lazy {pet}. -->');
$template->parse('output', 'pangram');
echo
'unit 5 ' . $template->tidy('output') . " \n";

// unit test 6 native comment
$template->setVar('pangram', '{# The {speed} {color} fox {action} over the lazy {pet}. #}');
$template->parse('output', 'pangram');
echo
'unit 6 ' . $template->tidy('output') . " \n";

// unit test 7 advanced logic
$template->setVar('pangram', '{!!if {printMe} == true !!}'
                          
.'The {speed} {color} fox {action} over the lazy {pet}.'
                          
.'{!endif}');
$template->parse('output', 'pangram');
echo
'unit 7 ' . $template->tidy('output') . " \n";

// unit test 8 simple logic
$template->setVar('pangram', '{!if printMe}'
                          
.'The {speed} {color} fox {action} over the lazy {pet}.'
                          
.'{!endif}');
$template->parse('output', 'pangram');
echo
'unit 8 ' . $template->tidy('output') . " \n";

// unit test 8A simple logic
$template->setVar('pangram', '{!if {printMe2}}'
                          
.'The {speed} {color} fox {action} over the lazy {pet}.'
                          
.'{!endif}');
$template->setVar('printMe2', 'printMe');
$template->parse('output', 'pangram');
echo
'unit 8A ' . $template->tidy('output') . " \n";

// unit test 9 global var
$template->setVar('pangram', '{$globalMe {speed},{color},{action},{pet} }');
$globalMe = 'The %s %s fox %s over the lazy %s.';
$template->parse('output', 'pangram');
echo
'unit 9 ' . $template->tidy('output') . " \n";

// unit test 10 object access
$template->setVar('pangram', '{@template getVar output @}');
$template->setVar('template', $template);
$template->parse('output', 'pangram');
echo
'unit 10 ' . $template->tidy('output') . " \n";

$elapsed = microtime(true) - $time;
echo
"\n elapsed $elapsed \n";

?>


For more information send a message to info at phpclasses dot org.