handlebars.js

Template reuse in meteor

自闭症网瘾萝莉.ら 提交于 2019-12-11 02:06:29
问题 I'm trying to reuse some control elements in my Meteor app. I'd like the following two templates to toggle visibility and submission of different forms. <template name='addControl'> <img class='add' src='/images/icon-plus.png' /> </template> <template name='okCancelControl'> <img class='submit' src='/images/icon-submit.png' /> <img class='cancel' src='/images/icon-cancel.png' /> </template> I'll call these templates in another: <template name='insectForm'> {{#if editing}} <!-- form elements -

How do I identify the current page in a page collection?

核能气质少年 提交于 2019-12-11 02:05:25
问题 I'm configuring a static site generator using Grunt's Assemble.io. I'm using the Pages Collection to build a navigation list like so: {{#each pages }} <li><a href="{{{filename}} }">{{{title}} }</a></li> {{/each }} I would also like to apply class="active" to the navigation item for the current page, but I'm not sure how to approach this. My first thought was to try comparing the title of the current iteration of the collection to that of the page being rendered, but this has two problems: The

Using Handlebars lookup with repetition

主宰稳场 提交于 2019-12-11 01:10:56
问题 Given an array of objects, I would like to use one property of a nested object to look up various properties in an associated object in Handlebars. In this example, I would like to show a list of students at each university, and information about the department to which each student belongs. My code works, but the nested lookups are very repetitive: {{lookup (lookup ../majors major) 'dean'}} {{lookup (lookup ../majors major) 'location'}} Is there anything I can do about this? I'd like to do

Create a Schema object in Mongoose/Handlebars with custom keys/values

不羁的心 提交于 2019-12-11 00:19:50
问题 I want to create a form to input custom keys and values of an object in an mongo/mongoose schema to eventually see in a handlebars view. See example to better explain. Any help would be great. :) Mongoose/Mongodb Schema: var docketSchema = new Schema({ staff: [{ String: String, String: String }] }); Handlebars input view: <div class="form-group"> <input value="{{input.staffkey1}}"> <input value="{{input.staffvalue1}}"> </div> <div class="form-group"> <input value="{{input.staffkey2}}"> <input

embed moment.js formatting in handlebars templates

半城伤御伤魂 提交于 2019-12-10 23:34:51
问题 I am trying get Moment.js date-time formating as part of my handlebars template. Actual Sample: <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <div id="hb-content"></div> <script id="hb-template" type="text/x-handlebars-template"> <small>Last restarted:</small> <code>moment({{last_started}}).format('dddd, MMMM Do');</code> <code>moment({{last_started}}).format('h:mma');</code> </script> <script type="text/javascript"> var temp = document.getElementById(

Switch case with default in handlebars.js

社会主义新天地 提交于 2019-12-10 22:19:37
问题 I want to implement a custom switch case with default value with the help of the Register Helper function in HandlebarsJs. Example: HTML: <div> {{#switch value}} {{#case 'a'}} A {{/case}} {{#case 'b'}} B {{/case}} {{#default 'C'}} {{/default}} {{/switch}} </div> JS: (The Register Helper function should work like the below pseudo code) switch(val) { case 1: return 'A'; break; case 2: return 'B'; break; default: return 'C'; } 回答1: Please go through the below examples, it will guide you step by

How can I create conditional row classes using Handlebars.js?

余生长醉 提交于 2019-12-10 22:17:11
问题 I Have a layout which is effectively structured as below <ul class="row"> <li>content</li> <li>content</li> <li>content</li> <li>content</li> <li>content</li> <li>content</li> <li>content</li> </ul> What i would like is that for every 5th item a new row to be created with a class of "row" so that my code can look as shown below <ul class="row"> <li>content</li> <li>content</li> <li>content</li> <li>content</li> <li>content</li> </ul> <ul class="row"> <li>content</li> <li>content</li> </ul>

Sails JS with EJS but linker to compile handlebars public templates

纵饮孤独 提交于 2019-12-10 21:39:43
问题 I'm a bit new to Node and javascript backend frameworks so please bear with me: I've been searching around to find a nice combination of front-end, back-end (MVC)frameworks to work with Node, and I've currently decided upon using SailsJS/EmberJS to make a boilerplate which I can play around with and maybe use for future projects. SailsJs (out of the box generated app) uses EJS to compile back-end views. EmberJs (by default, starter kit) uses handlebars to compile front-end views. I want to

Handlebar helper syntax in Ember CLI

帅比萌擦擦* 提交于 2019-12-10 21:28:15
问题 In this post Iterating over basic “for” loop using Handlebars.js An example of a 'repeat' helper is layed out. helper Handlebars.registerHelper('times', function(n, block) { var accum = ''; for(var i = 0; i < n; ++i) accum += block.fn(i); return accum; }); template {{#times 10}} <span>{{this}}</span> {{/times}} I can't seem to write this out the 'CLI' way... can someone enlighten me? First of all, it will be it's own helper file in /helpers , and it should have a dash so the resolver

How do you prevent newline added to Handlebars partial?

偶尔善良 提交于 2019-12-10 20:51:06
问题 Scenario: one-line Handlebars partial used in an inline element: Handlebars template: <a href="#section">{{> partial}}Label</a> Partial: <svg class="icon" viewBox="0 0 65 65"><use xlink:href="#icon"></use></svg> Compilation result: <a href="#section"><svg class="icon" viewBox="0 0 65 65"><use xlink:href="#icon"></use></svg> Label</a> As you see, partial comes across with the newline. There's no newline in the file. 回答1: It's on the handlebarsjs.com, but not documented well enough (for me);