PHP code example of epii / template-engine
1. Go to this page and download the library: Download epii/template-engine library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
epii / template-engine example snippets
$config = ["tpl_dir" => __DIR__."/view","cache_dir"=>__DIR__."/cache"];
\epii\template\View::setEngine($config);
$data = ["name" => "张三", "age" => "222","key_name"=>"name1","info"=>["name1"=>"李四"],
"list"=>[
["name"=>"任0"],
["name"=>"任1"],
["name"=>"任2"],
["name"=>"任3"]
]
];
\epii\template\View::display("a/index", $data);
View::fetch($file, $data);
View::display($file, $data);
View::fetchContent($content, $data);
View::displayContent($content, $data);
View::addCommonData(Array $data);//设置公共数据
//自定义规则
View::addStringRule($string_find, $string_replace);
View::addPregRule($preg_find, $replace_string);
View::addPregRuleCallBack($preg_find, callable $replace);
{$name} ,{$info.name1},{$info.$key_name}//方法一
echo $name;
{:rtrim,aaa\,,\,}// 相当于 echo rtrim("aaa,",",");
{:rtrim,aaa\,,$a} // 相当于 echo rtrim("aaa,",$a);
{:rtrim,aaa\,,aa\{$a\}bb} // 相当于 echo rtrim("aaa,","aa".$a."bb");
{? $a}
{? $a 1}
{? $a b}
echo isset($a)?$a:""
{$name?}
{$name?"张三"}
{$info["age"]?"18岁"}
{$info.age?"18岁"}
{loop $list.info?[]}
echo isset($name)?$name:($name="");