thinkphp 集成 twig模版引擎

下载地址:https://github.com/fucongcong/ThinkPHPLevel/archive/master.zip

 

控制器格式为:
<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){

        return $this->render(T('Index/index'),array(
            'hello'=>"张三11",'sss'=>'aaa')
        );
     }
    public function add(){
          
        $data = array(
                  0 => array(
                      "id" => 1 ,
                     "name" => "张三0",
                     "age" => 20,
                     "sex" => "女"
                   ),
                  1 => array(
                      "id" => 1 ,
                     "name" => "张三1",
                     "age" => 20,
                     "sex" => "女"
                   ),
                  2 => array(
                      "id" => 1 ,
                     "name" => "张三2",
                     "age" => 20,
                     "sex" => "女"
                   ),
        );
        $data1 = array(
             "name" => "王五"
            );
        var_dump($data);
        return $this->render(T('Index/add'),array('data'=>$data,"data1"=>$data1));//传递多维数组
    
     }
}
#twig 解析

{% extends './Public/layout.html.twig' %} {% block title%} {{group.title|default("")}} {% endblock %} {% block body %} {{ hello }} {{ data1.name }} {{ age }} {{ sex }}
<ul> {% for user in data %} <li>{{ user.name}}</li> {% else %} <li><em>no user 12132131found</em></li> {% endfor %} </ul> {{ data1['name'] }} {% endblock %}

 

posted @ 2015-11-20 10:01  麦田守望者~  阅读(523)  评论(0编辑  收藏  举报