PHP Classes

templater: Template engine that replaces marks and sections

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 253 All time: 7,888 This week: 560Up
Version License PHP version Categories
templater 1.0GNU General Publi...5.3PHP 5, Templates
Description 

Author

This class is a template engine that replaces marks and sections.

It can read a template from a file and replaces marks with given variable values.

It can also iterate over sections marked with {for} and {endfor} constructs iterating array variables.

Picture of Dmitro
  Performance   Level  
Name: Dmitro <contact>
Classes: 1 package by
Country: Ukraine Ukraine

Example

<?php
header
('Content-Type: text/html; charset=UTF-8');

define('BASE_PATH',$_SERVER['DOCUMENT_ROOT']);
define('TPL_DIR','/template/');

$ar['head'] = array(
    array(
'title' => 'index page')
);

$ar['data'] = array(
    array(
'title'=>'title'),
    array(
'text'=>'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.')
);

$ar['menu'] = array(
   
'0' => array('id'=>'11','text'=>'link 1'),
   
'1' => array('id'=>'23','text'=>'link 2'),
   
'2' => array('id'=>'54','text'=>'link 3')
);

$ar['list'] = array(
   
'0' => 'list 1',
   
'1' => 'list 2',
   
'2' => 'list 3'
);

$ar['Tpl'] = 'index.tpl.html';




include
BASE_PATH.'/templater.php';
$templater = new Templater;

$templater->AddVar('ar',$ar);
                   
$templater->Tpl = BASE_PATH.TPL_DIR.$ar['Tpl'];

$templater->Template();
?>


  Files folder image Files (6)  
File Role Description
Files folder imagetemplate (4 files)
Plain text file index.php Example example
Plain text file templater.php Class class

  Files folder image Files (6)  /  template  
File Role Description
  Plain text file head.tpl.html Data head
  Plain text file index.tpl.html Data template
  Plain text file left.tpl.html Data left
  Plain text file top.tpl.html Data top

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:253
This week:0
All time:7,888
This week:560Up
User Comments (1)
This is a very good and useful class ;-) But the PHP had a go...
9 years ago (José Filipe Lopes Santos)
70%StarStarStarStar