sudo vi /etc/php5/apache2/php.ini
把short_open_tag = Off
改成
short_open_tag = On
加入
extension=twig.so
/etc/init.d/apache2 restart
或
service apache2 restart
--------------------------------------------------------------
php程式 t1.php
<?php
//include "config.php";
//twig
require_once 'lib/Twig/Autoloader.php';
Twig_Autoloader::register();
$loader = new Twig_Loader_Filesystem('templates');
$twig = new Twig_Environment($loader);
$school=['湖東','湖南','湖北'];
//多維陣列
$school2=['schoolname'=>array('湖東','湖南','湖北'),
'class'=>array('40班','30班','33班'),
'stu'=>array('800人','700人','750人'),
];
echo $twig->render('t1.html', array('name' => '台灣','year'=>66,'school'=>$school,
'school2'=>$school2 ));
樣板網頁t1.html
自己設定變數
{% set f1 = 'good' %}
呼叫變數 {{f1}} <br>
{{name}} <br>
{{year}}<br>
{% if year > 55 %}
您超過55歲 <br>
{% else %}
您小於55歲 <br>
{% endif %}
<hr>
{% for pp in school %}
學校: {{ pp }}
<br>
{% endfor %}
<hr>
{% for i in range(0, 2) %}
學校:{{school2.schoolname[i]}} <br>
班級:{{school2.class[i]}} <br>
學生:{{school2.stu[i]}} <br>
<br>
{% endfor %}
沒有留言:
張貼留言