enzonagata/template-buffer

Template engine with php buffer

v0.2.9 2018-05-03 04:46 UTC

README

Only use files with *.phtml extension, for the moment can not be changed.

Class Template;

Get started

$View = new Template($container);

Configuring Layout path - Root directory

$dir = 'path/subpath';
$View->setLayoutPath($dir);

Configuring Templates path - Root directory

$dir = 'path/subpath';
$View->setTemplatePath($dir);

Create variables to access in to Templates and Layouts

$var = array(); || $var = (string); || $var = (integer);
$View->set('nome_variavel', mixed $var);

How to access variables in to Template or Layout files

<p>
   <?=$variable_name?>
</p>

<!-- With array -->
<ul>
<?php foreach($variable_name as $key => $item){?>
   <li><?= $key; ?> => <?= $item; ?></li>
<?php } ?>
</ul>

Rendering template

//Obs.: file name without extension
$View->render('file_name');

//If it is in a subdirectory of the configured Template folder.
//Obs.: file name without extension
$View->render('path_name/file_name');

Class Html;

This class has been extended by default in the Template class, and can be accessed with the public variable $View->Html

Adding CSS in Layout

//Don't write with extension *.css
$View->Html->addStyles(array(),$option(String('top','bottom')));
//ex:
$View->Html->addStyles(['styles','admin/index'],$option);

Displaying css in layout

<head>
<?=$this->Html->css('top');?>
</head>
<footer>
<?=$this->Html->css('bottom');?>
</footer>

Adding JS in Layout

//Don't write with extension *.js
$View->Html->addScripts(array(),$option(String('top','bottom')));
//ex:
$View->Html->addScripts(['scripts','admin/index'],$option);

Displaying JS in Layout

<head>
<?=$this->Html->js('top');?>
</head>
<footer>
<?=$this->Html->js('bottom');?>
</footer>

Displaying imagem

<body>
<?=$this->Html->image('nome_do_arquivo.extensão','classe_css');?>
</body>

Class Text;

This class has been extended by default in the Template class, and can be accessed with the public variable $View->Text

//Text clean
$this->Text->clean($string);

//Text excerpt
$this->Text->excerpt($string,$startPos=0,$maxLenght=100);

//Slugfy - Url Friendly
$this->Text->slugfy($text)