develhopper / primal
免费开源的PHP模板系统
1.5.1
2021-12-13 10:05 UTC
README
另一个模板引擎库
文档
安装
composer require develhopper/primal
示例
初始化 Primal
<?php use Primal\Primal; $primal = Primal::getInstance([ 'views_dir' => 'views directory', 'cache_dir' => 'directory path for caching' ]); $primal->view("viewname.html",[ 'arg1' => 'value' ]); // it will print the content of the view file
视图语法
打印变量
<h1>
{{$variable}}
</h1>
执行函数
{% var_dump($array); %}
包含另一个视图
@include('viewname.html')
占位符
"base.html"
<body>
@yield('content')
</body>
从另一个视图扩展
@extend('base.html')
通过 @section 在 base.html 中填充占位符内容
@extend('base.html') @section('content') <h1>{{$title}}</h1> <p>{{$content}}</p> @endsection
条件语句和 elseif
@if($variable == "foo") <p>foo</p> @elseif($variable == "bar") <p>bar</p> @else <p>foobar</p> @endif
for 和 foreach 循环
@for($i=0;$i<100;$i++) <p>{{$i}}</p> @endfor @foreach($list as $item) <p>{{$item}}</p> @endforeach