Which templating engine can I use with both JS and PHP? [closed]

筅森魡賤 提交于 2019-12-18 10:22:56

问题


I'm looking for a simple Template engine that works both on client side with JS ánd on server side with PHP.

That means I want to be able to use the same template definition for both use cases.

Do you know any templating engines that have official implementations in both JS and PHP?


回答1:


If you like JS->PHP priority :) then you have this two jquery-tmpl compatible template renderer for PHP backend

  1. https://github.com/abackstrom/jquery-tmpl-php
  2. https://github.com/xyu/jquery-tmpl-php

If you prefer more PHP->JS priority :) then you can try this Javascript implementation of popular PHP templating Smarty

  1. http://code.google.com/p/jsmart/

Or you can try something more neutral like:

  1. Mustache http://mustache.github.com/



回答2:


Do you mean something like mustache?




回答3:


You have a new option to compile templates for both PHP and JS using Twig + Twig.js

  • http://twig.sensiolabs.org/
  • https://github.com/schmittjoh/twig.js



回答4:


Use Mustache!

AFAIK, Mustache is the only template engine that has official implementations in both PHP and JS... along with two dozen programming/scripting languages.

  • Twig does have a JS version, but that's incomplete and AFAIK unofficial.

  • Smarty does have a JS version, but it's also an unofficial port... and Smarty is getting a bit outdated.



来源:https://stackoverflow.com/questions/6004060/which-templating-engine-can-i-use-with-both-js-and-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!