Skip to content

joanmon/TemplateEngine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lightweight PHP template engine

Features

  • Fast

  • Powerful

  • Easy

Installing

@todo

Getting started

  • Simple template:
/base/path/|
           |_ simple-template.phtml
           |_ script.php
<!-- simple-template.phtml -->
<!DOCTYPE html>
<html>
   <head>
       <title><?= \jmon\TplEngine\View::get('title') ?></title>
   </head>
   <body>
       <h1><?= \jmon\TplEngine\View::get('title') ?></h1>
   </body>
</html>
<?php
 // script.php
use jmon\TplEngine\View;
View::setBasePath('/base/path');
View::set('title', 'hello world!');
echo View::render('simple-template.phtml');
?>
<!-- final rendering -->
<!DOCTYPE html>
<html>
   <head>
       <title>hello world!</title>
   </head>
   <body>
       <h1>hello world!</h1>
   </body>
</html>
  • Template with layout:
/base/path/|
           |_ layout.phtml
           |_ home/index.phtml
           |_ script.php
<!-- layout.phtml -->
<!DOCTYPE html>
<html>
   <head>
       <title><?= \jmon\TplEngine\View::get('title') ?></title>
   </head>
   <body>
   		 <!-- Place where will be rendered the content of templates that extends this one -->
       <?= \jmon\TplEngine\View::content() ?>
   </body>
</html>
<!-- home/index.phtml -->
<?php \jmon\TplEngine\View::templateExtend('layout.phtml')?>
<h1><?= \jmon\TplEngine\View::get('title') ?></h1>
<?php
 // script.php
use jmon\TplEngine\View;
View::setBasePath('/base/path');
View::set('title', 'hello world!');
echo View::render('/home/index.phtml');
?>
<!-- final rendering -->
<!DOCTYPE html>
<html>
   <head>
       <title>hello world!</title>
   </head>
   <body>
       <h1>hello world!</h1>
   </body>
</html>
  • Use of partial:
/base/path/|
           |_ template.phtml
           |_ partial.phtml
           |_ script.php
<!-- template.phtml -->
<!DOCTYPE html>
<html>
   <head>
       <title><?= \jmon\TplEngine\View::get('title') ?></title>
   </head>
   <body>
       <h1><?= \jmon\TplEngine\View::get('title') ?></h1>
       <?php \jmon\TplEngine\View::partial('partial.phtml')?>
   </body>
</html>
<!-- partial.phtml -->
<footer><?= \jmon\TplEngine\View::get('footer-text') ?></footer>
<?php
 // script.php
use jmon\TplEngine\View;
View::setBasePath('/base/path');
View::set('title', 'hello world!');
View::set('footer-text', 'Awesome footer!');
echo View::render('template.phtml');
?>
<!-- final rendering -->
<!DOCTYPE html>
<html>
   <head>
       <title>hello world!</title>
   </head>
   <body>
       <h1>hello world!</h1>
       <footer>Awesome footer!</footer>
   </body>
</html>

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published