javascript 哪种模板引擎可以与 JS 和 PHP 一起使用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6004060/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 19:06:48  来源:igfitidea点击:

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

javascriptphphtmltemplate-enginetemplating

提问by Florian

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

我正在寻找一个简单的模板引擎,它可以在客户端使用 JS 和在服务器端使用 PHP。

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

这意味着我希望能够为两个用例使用相同的模板定义

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

你知道任何在 JS 和 PHP 中都有官方实现的模板引擎吗?

采纳答案by mPrinC

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

如果你喜欢JS->PHP 优先级:) 那么你有这两个用于 PHP 后端的 jquery-tmpl 兼容模板渲染器

  1. https://github.com/abackstrom/jquery-tmpl-php
  2. https://github.com/xyu/jquery-tmpl-php
  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

如果你更喜欢PHP->JS 优先级:) 那么你可以试试这个流行的 PHP 模板 Smarty 的 Javascript 实现

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

Or you can try something more neutral like:

或者你可以尝试一些更中性的东西,比如:

  1. Mustache http://mustache.github.com/
  1. 小胡子http://mustache.github.com/

回答by GromNaN

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

您有一个新选项可以使用 Twig + Twig.js 为 PHP 和 JS 编译模板

回答by robertc

Do you mean something like mustache?

你的意思是像胡子一样的东西吗?

回答by John Slegers

Use Mustache!

使用小胡子

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

AFAIK,Mustache 是唯一一个在 PHP 和 JS中都有官方实现的模板引擎......以及两打编程/脚本语言。

  • 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.

  • Twig 确实有一个 JS 版本,但这是不完整的,而且 AFAIK 是非官方的。

  • Smarty 确实有一个 JS 版本,但它也是一个非官方的端口……而且 Smarty 已经有点过时了。