在无脂框架模板中使用变量

时间:2014-08-18 09:44:54

标签: php templates fat-free-framework

我正在阅读无胖框架用户指南,并希望尝试显示使用F3自己的模板语言的模板。显示模板,但变量未替换,我不知道原因。

的index.php

$f3 = require('../f3/base.php'); // I moved the lib dir one level up
$f3->set('UI', 'ui/');

$f3->route('GET /*',
    function($f3) {
        $f3->set('test', 'foo');
        echo View::instance()->render('layout.html', 'text/html');
    }
);

$f3->run();

layout.html 只包含

{{ @test }}

这也正是显示的内容,而不是“foo”。 F3模板语言的其他指令似乎也不起作用。

我错过了先激活它的步骤还是什么?

1 个答案:

答案 0 :(得分:1)

您必须使用模板类而不是视图类

$f3 = require('../f3/base.php'); // I moved the lib dir one level up
$f3->set('UI', 'ui/');

$f3->route('GET /*',
    function($f3) {
        $f3->set('test', 'foo');
        echo Template::instance()->render('layout.html');
    }
);

$f3->run();