问题
I was wondering if there was something out there that would allow php to render Handlebarsjs templates on the server side.
thanks
回答1:
I start a new project to do this task, its here :
https://github.com/XaminProject/handlebars.php
Not so much tested but its usable enough.
回答2:
lightncandy is a pure PHP library that supports almost all features of handlebars (Does not require a PECL library)
回答3:
Try mustache.php it's not the same but handlebarsjs is based on it so it's very much alike.
回答4:
This heavily depends on how you are dealing with Handlebars templates. Are you embedding them in the HTML? Are you loading them separately? Are you saving them locally and then compiling? If you are embedding in HTML, you can just put some PHP tags there and you're done.
If you are loading them separately, you'll have to load the template file within PHP (e.g: file_get_contents, fopen/fread), process the information you want, and then save the file again (e.g.: file_put_contents, fopen/fwrite).
PHP can render anything. Just put your PHP open/close tags and do your magic.
来源:https://stackoverflow.com/questions/11282417/handlebarsjs-php-rendering