enzonagata / template-buffer
带有 PHP 缓冲区的模板引擎
v0.2.9
2018-05-03 04:46 UTC
Requires
- php: >=7.1.0
README
目前只能使用 *.phtml 扩展名的文件,暂时无法更改。
类 Template;
开始使用
$View = new Template($container);
配置布局路径 - 根目录
$dir = 'path/subpath'; $View->setLayoutPath($dir);
配置模板路径 - 根目录
$dir = 'path/subpath'; $View->setTemplatePath($dir);
创建变量以在模板和布局中使用
$var = array(); || $var = (string); || $var = (integer); $View->set('nome_variavel', mixed $var);
如何在模板或布局文件中访问变量
<p> <?=$variable_name?> </p> <!-- With array --> <ul> <?php foreach($variable_name as $key => $item){?> <li><?= $key; ?> => <?= $item; ?></li> <?php } ?> </ul>
渲染模板
//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');
类 Html;
这个类默认扩展了 Template 类,可以通过公共变量 $View->Html 访问
在布局中添加 CSS
//Don't write with extension *.css $View->Html->addStyles(array(),$option(String('top','bottom'))); //ex: $View->Html->addStyles(['styles','admin/index'],$option);
在布局中显示 CSS
<head> <?=$this->Html->css('top');?> </head> <footer> <?=$this->Html->css('bottom');?> </footer>
在布局中添加 JS
//Don't write with extension *.js $View->Html->addScripts(array(),$option(String('top','bottom'))); //ex: $View->Html->addScripts(['scripts','admin/index'],$option);
在布局中显示 JS
<head> <?=$this->Html->js('top');?> </head> <footer> <?=$this->Html->js('bottom');?> </footer>
显示图像
<body> <?=$this->Html->image('nome_do_arquivo.extensão','classe_css');?> </body>
类 Text;
这个类默认扩展了 Template 类,可以通过公共变量 $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)