xmeltrut/wing-commander

Flight 微框架的 Mustache 模板库包装器

1.2.0 2015-12-30 21:57 UTC

This package is auto-updated.

Last update: 2024-09-24 02:37:07 UTC


README

Latest Stable Version License

Wing Commander 是 Flight PHP 微框架的 Mustache 包装器。

安装

安装 Wing Commander 最简单的方法是使用 Composer。在项目的根目录下创建一个 composer.json 文件,并要求 Wing Commander。

{
    "require": {
        "xmeltrut/wing-commander": "*"
    }
}

然后运行安装命令,这将安装所有依赖项 - 包括 Flight 和 Mustache。

composer install

用法

基本用法如下。

require 'vendor/autoload.php';

WingCommander::init();

Flight::route('/', function(){
    Flight::view()->set("someVar", "Hello, World!");
    Flight::render("homepage", array(), "body");
    Flight::render("layout", array("title" => $pageTitle));
});

Flight::start();

默认情况下,它将在项目的 ./templates 目录中查找 Mustache 模板。您可以通过调用 setTemplatePath 方法来更改此设置。

Flight::view()->setTemplatePath("./application/templates");

让我们创建 homepage.mustache。

<p>{{someVar}}</p>

还要创建一个布局来包裹它 - layout.mustache。

<p>Wing Commander says:</p>
{{{body}}}

将所有这些放在一起,您可以使用它就像使用标准的 Flight 视图组件一样。

Flight::view()->set("someVar", "Hello, World!");
Flight::render("homepage", array(), "body");
Flight::render("layout", array("title" => $pageTitle));

进一步阅读