質問

I am in the process of building a database website. I am currently constructing the various webpages. For my search results, I would like to use a client side templating engine. I have not used one before and have a quick question:

I see that many of the templating engines (I have researched Handlebars.js and dust.js the most) need to be installed on the command line (as opposed to simply included as a library like jQuery). While I am currently developing on a mac using MAMP and can install them locally, does this mean I would also need to install it on the public server the webapp will sit on when live?

I have wondered whether the installation is necessary for the compiler and you then simply upload pre-compiled templates that require no extra code/installation.

If anyone could clarify, that would be very helpful.

役に立ちましたか?

解決

You don't have to install the template engine locally to be able to use them. Actually, using template engines in the client can be done in 2 different ways, the far I know:

On-the-fly compiling and rendering
You download the plain template file (.hbs, .dust, .mustache, etc) via AJAX or put them in the middle of your HTML, like using <script type="text/template">...</script>
Then, you pass it to the engine's compile() and render() functions. The engine .js file needs to be included in your page.

This is good for when you're development environment, but bad for production cases.

Pre-compiled templates and then rendering
You download the pre-compiled template (an .js file with a function which will return the HTML) via AJAX and then call your engine's render() function.
This is the opposite of the above technique, and would require you to have the engine lib installed in some way locally, to allow you to pre-compile them before going to production.

Also, you may not need to include the engine lib in your page, depending on how the engine compiles your template.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top