handlebars.js

Insert html in a handlebar template without escaping

╄→尐↘猪︶ㄣ 提交于 2019-11-27 06:38:52
Is there a way to insert a string with html tags into a handlebars template without getting the tags escaped in the outcoming string? template.js: <p>{{content}}</p> use the template HBS.template({content: "<i>test</i> 123"}) actual outcome: <p><i>test</i> 123</p> expected result: <p><i>test</i> 123</p> Praveen Try like <p>{{{content}}}</p> I got the official reference to support my answer: Handlebars HTML-escapes values returned by a {{expression}} . If you don't want Handlebars to escape a value, use the "triple-stash", {{{ . In your template you must add triple mustaches like this. <p>{{

How to iterate over array of objects in Handlebars?

↘锁芯ラ 提交于 2019-11-27 06:31:15
This might seem a silly question but I can't seem to find the answer anywhere. I'm hitting this Web Api that returns an array of objects in JSON format: Handlebars docs shows the following example: <ul class="people_list"> {{#each people}} <li>{{this}}</li> {{/each}} </ul> in the context of: { people: [ "Yehuda Katz", "Alan Johnson", "Charles Jolley" ] } In my case I don't have a name for the array, it's just the root object of the response. I've tried using {{#each}} with no luck. First time using Handlebars... what am I missing? UPDATE Here's a simplified fiddle to show what I'm asking: http

Iterating over basic “for” loop using Handlebars.js

旧城冷巷雨未停 提交于 2019-11-27 06:22:09
I’m new to Handlebars.js and just started using it. Most of the examples are based on iterating over an object. I wanted to know how to use handlebars in basic for loop. Example. for(i=0 ; i<100 ; i++) { create li's with i as the value } How can this be achieved? There's nothing in Handlebars for this but you can add your own helpers easily enough. If you just wanted to do something n times then: Handlebars.registerHelper('times', function(n, block) { var accum = ''; for(var i = 0; i < n; ++i) accum += block.fn(i); return accum; }); and {{#times 10}} <span>{{this}}</span> {{/times}} If you

Handlebars templating and dynamic images

一世执手 提交于 2019-11-27 06:02:22
问题 In my templates I am doing something like <img class="someClass" src="{{imgURL}}"> The images are loaded correctly but I get warnings like: GET http://localhost:8888/%7B%imgURL%7D%7D 404 (Not Found) Is there a way to fix this? 回答1: You have two problems: You're missing a closing quote in your <img> but that's not a big deal. Your template is being stored in a hidden <div> or similar element that contains HTML. If you say this: <div id="t" style="display: none"> <img class="someClass" src="{

Access a variable outside the scope of a Handlebars.js each loop

倾然丶 夕夏残阳落幕 提交于 2019-11-27 06:01:18
I have a handlebars.js template, just like this: {{externalValue}} <select name="test"> {{#each myCollection}} <option value="{{id}}">{{title}} {{externalValue}}</option> {{/each}} </select> And this is the generated output: myExternalValue <select name="test"> <option value="1">First element </option> <option value="2">Second element </option> <option value="3">Third element </option> </select> As expected, I can access the id and title fields of every element of myCollection to generate my select. And outside the select, my externalValue variable is correctly printed ("myExternalValue").

conditional on last item in array using handlebars.js template

北慕城南 提交于 2019-11-27 05:15:12
问题 I am leveraging handlebars.js for my templating engine and am looking to make a conditional segment display only if it is the last item in array contained in the templates configuration object. { columns: [{<obj>},{<obj>},{<obj>},{<obj>},{<obj>}] } I've already pulled in a helper to do some equality/greater/less-than comparisons and have had success identifying the initial item this way but have had no luck accessing my target array's length. Handlebars.registerHelper('compare', function

Handlebars.js if block helper ==

允我心安 提交于 2019-11-27 04:28:05
How would you change the following code to make it work? The problem is the this == 'some message' expression: <ul> {{#each errors}} {{#if (this == 'some message') }} <li>Status</li> {{else}} <li>{{this}}</li> {{/if}} {{/each}} </ul> The easiest thing would be to add a custom if_eq helper: Handlebars.registerHelper('if_eq', function(a, b, opts) { if(a == b) // Or === depending on your needs return opts.fn(this); else return opts.inverse(this); }); and then adjust your template: {{#if_eq this "some message"}} ... {{else}} ... {{/if_eq}} Demo: http://jsfiddle.net/ambiguous/d4adQ/ If your errors

Is there any way to use multiple view engines with Express + Node.js

十年热恋 提交于 2019-11-27 04:20:50
问题 Scenario : I had developed some transactional pages using Node.js, Express + Handlebars as view engine and MongoDB. Now the issue is during module integration I got some of the pages which are built on Express + Jade as view engine. Question : How to integrate pages built on Handlebars & some on Jade ? 回答1: Add both engines and consolidate.js in your package.json In yourapp.js var engines = require('consolidate'); app.engine('jade', engines.jade); app.engine('handlebars', engines.handlebars);

Setting up rake-pipeline for use with handlebars alongside Google App Engine

我的梦境 提交于 2019-11-27 04:04:28
问题 So here's what I'm attempting to do. I'm building an ember.js application, with a java backend running on GAE. I'm using handlebars, but I want them divided up into separate files, not just all pasted into the index.html. Via the ember.js irc I was turned on to rake-pipeline along with minispade Along with the web filters and a custom handlebars filter I started building the assetfile. I don't know Ruby, or gem files, etc. So I'm trying to figure out the best way to be able to compile my

How to change the default delimiter of Handlebars.js?

孤街醉人 提交于 2019-11-27 03:13:23
问题 I need to use handlebars.js and I also use Blade template engine from Laravel (PHP Framework). The tags {{}} conflict with blade's placeholders that are exactly the same. How can I change those {{var}} to something like <% var %> ? 回答1: This is not possible with "standard" Handlebars. https://github.com/wycats/handlebars.js/issues/227 回答2: Although it may be true that you can't configure Handlebars' expression delimiters, that's not the only way to resolve the conflict between Handlebars and