handlebars.js

How to insert JavaScript code in a Handlebars template?

拈花ヽ惹草 提交于 2020-08-05 06:19:57
问题 Quoting Handlebars FAQ: How can I include script tags in my template? If loading the template via an inlined tag then you may need to break up the script tag with an empty comment to avoid browser parser errors: <script type="text/x-handlebars"> foo <scr{{!}}ipt src="bar"></scr{{!}}ipt> </script> Nevertheless, I can't seem to be able to implement this: document.getElementById('output').innerHTML = Handlebars.compile( document.getElementById("template").innerHTML )({}); <script src="https:/

Vue: Displaying nested data in a table

点点圈 提交于 2020-06-24 13:58:29
问题 I'm in the process of rewriting some older code, and using Vue as the replacement. It's all going great apart from changing one table that is templated using handlebars. Using handlebars nested {{each}} I can work down through the nested data structure while displaying the relevant data in table rows: e.g. using handlebars: https://jsfiddle.net/6dsruo40/1/ I cant figure out how to do the same using Vue with v-for etc. Fiddle with as mush as I have: https://jsfiddle.net/cj7go6bv/ I don't know

How to use {{{{raw-helper}}}} in a handlebars template

最后都变了- 提交于 2020-05-29 06:59:07
问题 I have a handlebars template that works great. I'd like to be able to put the following in it: <script id="someTemplate" type="text/x-handlebars-template"> <div class="editStuff"> <span {{#if aThing}} data-someKey="{{anotherThing}}" {{/if}}> {{aThirdThing}} </span> </div> </script> This obviously would render when the handlebars file is processed. all of the {{}}'s end up being blank, no good. I found the {{{{raw-helper}}}} block helper, and tried it out like so: {{{{raw-helper}}}} <script id

Registering handlebars helpers with node does absolutely nothing

末鹿安然 提交于 2020-05-26 04:59:06
问题 I'm attempting to write my own handlebars helpers and am getting no where. I'm using the npm hbs package (Handlebars.registerHelper didn't work) and registering it in app.js like so: app.set('view engine', 'hbs'); var hbs = require('hbs'); hbs.registerHelper("log", function(something) { return console.log(something); }); hbs.registerHelper('test', function() { return console.log('test') }); Yet {{log 'test'}} or {{test}} any where inside my template does absolutely nothing. There's no js

Is it possible to assign a parameter value within handlebars templates without using helpers?

泪湿孤枕 提交于 2020-05-25 05:45:32
问题 I am trying to assign values within a template, the idea is to do something like this: {{#if author}} {{className = 'classA'}} <- trying to implement this line. {{else}} {{className = 'classB'}} {{/if}} <div class={{className}}></div> Is it possible to do so without registerHelper? 回答1: You can do this with a partial. partial: <div class="{{classname}}">{{var1.author}}</div> template: {{#if author}} {{> mypartial var1=. classname="classA"}} {{else}} {{> mypartial var1=. classname="classB"}} {

Bootstrap navbar-toggler-icon not visible but functioning normally [duplicate]

拥有回忆 提交于 2020-05-08 06:32:46
问题 This question already has an answer here : Bootstrap navbar: nothing is displayed on smaller devices (1 answer) Closed 19 days ago . I am trying to get my bootstrap navbar implemented into my handlebars layout file. I've noticed some weird things happening with bootstrap and this is no exception. Once I shrink my window to a size where the navbar-toggler-icon should show, it is not visible, but it is still functioning there like it should, I just can't see it. Here is my entire layout.hbs

Handlebarsjs check if a string is equal to a value

人盡茶涼 提交于 2020-04-07 14:44:31
问题 Is it possible in Handlebars to check if a string is equal to another value without registering a helper? I can't seem to find anything relevant to this in the Handlebars reference. For example: {{#if sampleString == "This is a string"}} ...do something {{/if}} 回答1: It seems you can't do it "directly" Try use helper, why not? Register helper in your javascript code: Handlebars.registerHelper('ifEquals', function(arg1, arg2, options) { return (arg1 == arg2) ? options.fn(this) : options.inverse

How to compare a value in handlebars?

情到浓时终转凉″ 提交于 2020-03-22 09:47:20
问题 I want display different HTML depending on a condition. It doesn't seem to compare those two values and it always shows the first variant. How can I compare the predefined values to the original value from JSON so that it can execute properly? {{#each this}} {{#each visits}} <div class="row"> {{#if variable_from_json }} <div class="col-lg-2 col-md-2 col-sm-2"> <i class="fa fa-home"></i> </div> {{else}} <div class="col-lg-2 col-md-2 col-sm-2"> <i class="fa fa-plus symbol-hospital"></i> </div>

Handlebars Block Helper : each with sort

☆樱花仙子☆ 提交于 2020-03-01 02:04:44
问题 I have an array of json objects which I output using a Handlebars template; I am currently doing using {{#each object}}...{{/each}}. I now need to sort the objects by one of the object's properties, which again is no problem using a handlebars helper & coffeescript, however, I have a problem in my template in that I cannot work out how to iterate over the sorted array using each. My research so far indicates that I probably need to write a custom Handlebars helper which will, in effect, be: {

Express and Handlebars: Implementing multiple themes

为君一笑 提交于 2020-02-06 07:52:49
问题 I and the team got a task to implement multiple themes for our project (keeping in mind that we have a single-theme project right now). By theme I don't mean just CSS , I mean different markup files, certain features for certain things, etc. (If you don't like the word 'theme' in this context don't use it, I hope you get the idea: some things need to be reused across the codebase, some things need to be specific to a theme ). Overall, we have no problem of structuring it in a maintainable way