简体   繁体   中英

Templating language for both Ruby and client-side JS

Is there a templating language that has both server-side ruby (pref. rails) and JS renderer?

Here is why this would be useful: Consider you want to display a big list of songs. You render the first 50 and a "show more" button.

"Show more" would link to the next 50 songs or would load those with AJAX if JavaScript is enabled.

The simple solution is to return a rendered piece of HTML from the server, but consider how nice would it be songs were returned as JSON and then were rendered using the same template on the client side.

Mustache .

It is Ruby based but there are several different implementations, including JS.

hamlc支持双方...... slim也有客户端版本,它被称为skim。

Node.js offers the appeal of using javascript on both the server and client side. If you are looking for something more ruby-on-rails like, then check out express.js which is a web-framework built on Node.js. Both of these are server-side frameworks but they offer libraries which can be used on the client side.

Something to keep in mind is that if you are rendering views from JSON data on the client side then you will need to have the client load the javascript libraries to perform these operations and then render the views - which may be a costlier operation. That said, if your view is simple enough, you can always write a simple javascript function of your own to render your JSON data rather than relying on an entirely new framework and view renderer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM