如何将 Mustache 与 Symfony 集成?
我想用 Mustache 替换 symfony1.4 的默认模板。令我惊讶的是,我通过谷歌搜索找不到相关的方法。
然后,我想我可以用简单的方式做到这一点。
public function executeIndex(sfWebRequest $request)
{
include('/path/to/Mustache.php');
$m = new Mustache();
echo $m->render('Hello {{planet}}', array('planet' => 'World!'));
return sfView::NONE;
}
这看起来很笨拙。主要问题是:
在哪里存储胡子模板(在我的例子中是“Hello {{planet}}”)?
是否可以替换默认的视图处理程序?这样我就可以将胡子模板放在模板文件夹中并对操作透明?
谢谢
I'd like to replace default template of symfony1.4 with Mustache. To my surprise, I cannot find related approach by Google search.
Then, I suppose I can do it in simple way.
public function executeIndex(sfWebRequest $request)
{
include('/path/to/Mustache.php');
$m = new Mustache();
echo $m->render('Hello {{planet}}', array('planet' => 'World!'));
return sfView::NONE;
}
This looks clumsy. The main problems are:
Where to store the mustache template('Hello {{planet}}' in my case)?
Is it possible to replace default View Handler? so that I can put mustache template in templates folder and be transparent to action?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为实现它的最佳方法是创建一个新的 sfView 实现。目前,
sfPhpView
是渲染输出的默认类。您可以扩展此类,并使用 Mustache 进行渲染。您可以查看 sfSmartyPlugin 来了解他们如何实现 Smarty 模板引擎...
I think the best way to implement it, is to create a new
sfView
implementation. Currently thesfPhpView
is the default class for rendering the output. You could extend this class, and use Mustache for the rendering.You could take a look sfSmartyPlugin to see how they have implemented the Smarty Template Engine...
也许你可以看看twig。它与 musatche 类似,并且与 symfony 具有良好的集成(twig 由 symfony 的创建者 Fabien Potencier 制作)。
这是 symfony 1.x 的插件: https://github.com/henrikbjorn/sfTwigPlugin
Maybe you can take a look to twig. It's similar to musatche, and have a fair integration with symfony (twig is made by Fabien Potencier, the creator of symfony).
This is the plugin for symfony 1.x : https://github.com/henrikbjorn/sfTwigPlugin