What template languages ​​are suitable for JS and PHP?

I am looking for a boilerplate “language” that works for both PHP and JS. I looked at Mustache (has a very limited if) and a few others like jquery-tmpl-php . So far, none of them meet all my criteria:

  • Works with data provided by JSON (array, map, literal)
  • Has an "if" operator that can at least check if
    • There is a key in the card.
    • list item is first / last / odd / even
    • The value is literal
  • You can iterate over the list (iterating over the keys on the map will be a bonus)
  • The same template and data generate exactly the same result with PHP and JS
  • fast enough (I know this is a bit vague)
  • Preferably do not complete the compilation step
  • Bonus: A good way to “pluralize” texts and basically everything that simplifies the i18n.
  • Not smarty :)

I appreciate any ideas, suggestions or tips.

Thanks Marek

+4
source share
1 answer

I just wrote this whole post just to re-read your question and see “not Smarty”: P. I will just say that I looked at the JS and PHP template library for a while, and Smarty seemed to be the best option for me. You say that Mustache is not enough. The only thing that comes to mind with the functionality of JS and PHP is Haml .

Original:
I have no experience with this, but I started using Smarty PHP templates. I create one Smarty template and send JSON to the client for Ajax requests. Then I use this JS Smarty engine for client-side processing. If the client does not support Javascript, I can gracefully degrade by simply sending the PHP-related array to the Smarty server server, instead of sending it to the JSON parser. Still using the same .smarty file, which works pretty well, and I think I will continue to use this methodology for the rest of my project.

+2
source

Source: https://habr.com/ru/post/1393255/


All Articles