How to integrate Mustache with Symfony?
I'd like to replace default template of symfony1.4 with Mustache. To my surprise, I c开发者_如何学JAVAannot 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
I think the best way to implement it, is to create a new sfView
implementation. Currently the sfPhpView
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...
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
精彩评论