cmgdevs/pure-template

为纯PHP项目提供的简单而强大的模板渲染

dev-main 2021-03-14 14:37 UTC

This package is auto-updated.

Last update: 2024-09-29 05:56:26 UTC


README

为纯PHP项目提供的简单而强大的模板渲染

#安装

composer require cmgdevs/pure-template:dev-main

preload ready in LWFramework (https://github.com/cmgcenter/pureTemplate)

#在纯PHP中初始化

在index.php中,您必须添加一个调用视图函数的调用,并传入2个变量

function view($file, $data)
{
	$viewPath = 'path/To/ViewFiles/'; 
	$layoutPath ='path/to/layout/';
	$cachePath = 'path/to/cacche/';
	$template = new \CMGDevs_PureTemplate\Pure($viewPath, $layoutPath, $cachePath);
	return $template->view($file, $data);
}

创建布局骨架

查看Wiki(https://github.com/cmgcenter/pureTemplate/wiki)

如何使用

循环 foreach

<?php
$names = ['ana'=>45, 'cris'=>100,'robert'=>34];`
?>
<?php
{ foreach ($names as key => $value): }
<ul>
	<li>{{$key}} - {{$value}}</li>
</ul>
{ endforeach }
?>

输出

ana - 45 cris - 100 robert - 34

循环 for

<?php
{ for($i=0; $i<10; $i++ )}
echo {{array[$i]}}
{endfor}
?>