Skip to content
This repository has been archived by the owner on Sep 12, 2020. It is now read-only.

chefe/TinyPHPHelperClasses

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TinyTemplateEngine

A small one file php template engine

Supporte Placeholder

  • {Title} for Variable
  • {IF:Condition}, {ELSE} and {ENDIF} for IF statements
  • {LOOP:Loopvariable} and {ENDLOOP} for loops

PHP-Code

// Include File
require_once('template.class.php');

// Create a new Template
$tpl = new Template('page.tpl');

// Build up data structure for template
$peoples = array();
$peoples[0] = array('name' => 'miller', 'surname' => 'peter');
$peoples[1] = array('name' => 'stone', 'surname' => 'frank');

// Fill up template with values
$tpl->assign('title', 'TinyTemplateEngine');
$tpl->assign('subtitle', 'A small one file php template engine');
$tpl->assign('looptitle', 'Now comes a loop:');
$tpl->assign('people', $peoples);
$tpl->assign('footer', 'This is the end of the template!');

// Display the template
$tpl->display();

Template

<html>
  <head>
    <title>{title}</title>
  </head>
  <body>
    <h1>{subtitle}</h1>
    
    <p>{looptitle}</p>
    {LOOP:people}
    <b>{name}</b> {surname}<br />
    {ENDLOOP}
    
    <br /><br />
    <i>{footer}</i>
  </body>
</html>

Result

<html>
  <head>
    <title>TinyTemplateEngine</title>
  </head>
  <body>
    <h1>A small one file php template engine</h1>
    
    <p>Now comes a loop:</p>
    <b>miller</b> peter<br />
    <b>stone</b> frank<br />
    
    <br /><br />
    <i>This is the end of the template!</i>
  </body>
</html>

About

A small one file php template engine

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages