zombor / kostache
Kohana 框架的无逻辑视图/Mustache 模块
v4.0.3
2014-05-08 14:53 UTC
Requires
- php: >=5.3.0
- mustache/mustache: ~2.6.0
This package is not auto-updated.
Last update: 2024-09-24 07:27:15 UTC
README
Kostache 是一个用于在您的应用程序中使用 Mustache 模板的 Kohana 3 模块。
使用方法
要使用,只需创建一个 POPO (Plain Old PHP Object) 如下所示
<?php class View_Test { public $hello = 'world'; public function testing() { return 'foobar'; } }
然后创建一个 Mustache 渲染器。引擎方法的参数是要使用的模板名称。
<?php $renderer = Kostache::factory();
然后进行渲染
<?php $this->response->body($renderer->render(new View_Test));
模板
模板应放在您的分层文件系统中的 templates/
目录中。它们应该有 .mustache 扩展名。
部分
部分将根据模板中使用的名称自动加载。因此,如果您在模板中引用 {{>foobar}}
,它将寻找 templates/partials/foobar.mustache
中的该部分。
布局
KOstache 支持布局。要使用,只需添加一个 templates/layout.mustache
文件(已提供了一个简单的示例),然后使用 Kostache_Layout
而不是 Kostache
作为您的渲染器。您可能想在视图类中放置一个 $title
属性。布局应包括一个 {{>content}}
部分以渲染页面的主体。
附加信息
有关具体使用和文档,请参阅