client-side-templating

Place client-side JavaScript templates in HTML or JavaScript?

你。 提交于 2019-12-05 07:55:11
Should client-side templates like the following (using underscore's templating engine): <p class="foo"><%= bar %></p> be placed in an separate HTML file, or a separate JavaScript file? I know it could work both ways. For example, a JavaScript file could just contain a list of string variables like so: var cute = '<p class="the"><%= unicorn %></p>'; var fb = '<p class="new-design"><%= sucks %></p>'; But I have also seen the following: <script type="text/template" id="omg-template"> <span id="swag-name"><%= name %></span> </script> Just from a Separation of Concerns standpoint, where does the

Getting the last element from a JSON array in a Handlebars template

非 Y 不嫁゛ 提交于 2019-12-01 05:20:05
So, I found that array elements can be accessed in Handlebars using: {{myArray.2.nestedObject}} and {{myArray.0.nestedObject}} ..to get the third and first elements for instance. ( handlebars-access-array-item ) Is there a way to get the last element from an array? I tried creating a helper for it: Handlebars.registerHelper("lastElement", function(array) { return array.last(); //Array.prototype extension }); ...and calling it as follows in the template: {{lastElement myArray}} or even {{lastElement myArray.lastElement nestedArray}} Sadly, this doesn't work. Helper functions return strings

Getting the last element from a JSON array in a Handlebars template

穿精又带淫゛_ 提交于 2019-12-01 03:12:56
问题 So, I found that array elements can be accessed in Handlebars using: {{myArray.2.nestedObject}} and {{myArray.0.nestedObject}} ..to get the third and first elements for instance. (handlebars-access-array-item) Is there a way to get the last element from an array? I tried creating a helper for it: Handlebars.registerHelper("lastElement", function(array) { return array.last(); //Array.prototype extension }); ...and calling it as follows in the template: {{lastElement myArray}} or even {

One-off rendering of an angular template string

旧巷老猫 提交于 2019-11-30 20:01:40
问题 I am writing a directive to integrate SlickGrid with my angular app. I want to be able to configure SlickGrid columns with an angular template (instead of a formatter function). To achieve this, I need the directive to dynamically create formatter functions that return HTML as a string. My approach has been to create a temporary scope, link the template against that, capture the html, and then destroy the scope. This works, but complains that $digest already in progress . Is there a way I can

Does handlebars.js replace newline characters with <br>?

一世执手 提交于 2019-11-30 12:04:34
问题 Trying to use handlebars.js for templating but the library seems to ignore newlines. What is the correct way to deal with newlines? Should they be replaced manually after the templating action? 回答1: It doesn't do so automatically, but using the helpers feature this can be achieved: JS: Handlebars.registerHelper('breaklines', function(text) { text = Handlebars.Utils.escapeExpression(text); text = text.replace(/(\r\n|\n|\r)/gm, '<br>'); return new Handlebars.SafeString(text); }); HTML template:

Client-side templating language with java compiler as well (DRY templating)

送分小仙女□ 提交于 2019-11-30 06:47:06
问题 I want to be able to define templates once and use them to render html from both the server-side as well as the client-side. (DRY principle and all that) The API that I'm envisioning is simply this: render(JSON, template) --> html. I'm using a java-framework (actually Play framwork, but I don't think this is framework specific). I've read a lot of similar questions, the latest, and most helpful being: Templating language for both client-side and server-side rendering. I pretty much agree with

Does handlebars.js replace newline characters with <br>?

隐身守侯 提交于 2019-11-30 01:20:17
Trying to use handlebars.js for templating but the library seems to ignore newlines. What is the correct way to deal with newlines? Should they be replaced manually after the templating action? Uri It doesn't do so automatically, but using the helpers feature this can be achieved: JS: Handlebars.registerHelper('breaklines', function(text) { text = Handlebars.Utils.escapeExpression(text); text = text.replace(/(\r\n|\n|\r)/gm, '<br>'); return new Handlebars.SafeString(text); }); HTML template: <div> {{breaklines description}} </div> Douglas Adam Smith II By inserting three braces instead of the

Client side and Server side rendering of ejs template

你。 提交于 2019-11-29 15:39:21
I always wanted to learn NodeJS to be able to run the same code on server and client side. I am using NodeJS with Express and EJS. So. I have a .ejs page with lot's of HTML, JS, CSS and a small bit with template. For the sake of justice let it be like this: the_list-->some.ejs <ul> <% for(i=0;i>the_list.length;i++) { %> <li>the_list[i]</li> <% } %> </ul> After some rendering on the server we have a perfect list. So. Now I want to rerender it on the client. I made some ajax request and now I have new items in the_list. What is the right way? As per ejs templates documentation var template = new

Basic Example of Client Side Templating with Dust.js

倾然丶 夕夏残阳落幕 提交于 2019-11-28 23:13:04
This is my first foray into client-side templating and I want to make sure I'm understanding it and using it correctly. After reading this LinkedIn engineering blog , I decided to go with dust.js rather than mustache or handlebars . Note that this stackoverflow post answered many of my questions, but I still have a few things I want to clarify. In the environment I work in I have no access to anything on the server side, so everything I create has to be able to run entirely in the client's browser. For this example, I'll try to recreate this code sample from the LinkedIn Dust Tutorial . I

Client-side templating language with java compiler as well (DRY templating)

狂风中的少年 提交于 2019-11-28 21:38:56
I want to be able to define templates once and use them to render html from both the server-side as well as the client-side. (DRY principle and all that) The API that I'm envisioning is simply this: render(JSON, template) --> html. I'm using a java-framework (actually Play framwork, but I don't think this is framework specific). I've read a lot of similar questions, the latest, and most helpful being: Templating language for both client-side and server-side rendering . I pretty much agree with the author that obvious contenders like: Mustache and Google Closure Templates are not going to cut