【问题标题】:Using variables in fat-free framework template在脱脂框架模板中使用变量
【发布时间】:2014-08-18 09:44:54
【问题描述】:

我正在阅读 fat-free 框架用户指南,并想尝试显示一个使用 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 模板语言的其他指令似乎也不起作用。

我是否错过了先激活它的步骤或其他什么?

【问题讨论】:

    标签: php templates fat-free-framework


    【解决方案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();
    

    【讨论】:

    • 我刚刚在 F3 Google Group 中找到了您对类似问题的回答。早该去那边看看的。还是谢谢你!
    猜你喜欢
    • 1970-01-01
    • 2012-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-14
    • 2011-10-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多