Home  >  Article  >  php教程  >  简单快速的php模板引擎

简单快速的php模板引擎

PHP中文网
PHP中文网Original
2016-05-26 08:18:381199browse

简单快速的php模板引擎

1.调用

<?php
require &#39;view.php&#39;;
 
$view=new view();
 
//第一种设置输出参数的方法
$view->setAttr("title", "Variable example");
//第二种设置输出参数的方法
$view->array = array(
            &#39;1&#39; => "First array item",
            &#39;2&#39; => "Second array item",
            &#39;n&#39; => "N-th array item",
);
$view->j = 5;
//输入页头、内容、页脚
$view->display("header.php")->display(&#39;index.php&#39;)->display(&#39;footer.php&#39;)->render();

2.theme/views/index.php

{comment}
这是注释
{/comment}
{if $array}
  {foreach $array as $key => $value}
    {$key} => {$value}<br />
  {/foreach}
{else}
  {/*}这也是注释{*/}
  <p>Array is empty!</p>
{/if}
 
{$i = 1}
{while $i < $j}
  当前 no. {$i}<br />
  {$i++}
{/while}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn