handlebarshelper

How can one render Handlebars variables inside a custom helper block?

◇◆丶佛笑我妖孽 提交于 2020-12-08 04:50:21
问题 I'm trying to get two Handlebars variables to render inside a custom Handlebars helper I've created. I'm using the Express.js view engine for handlebars.js, and in my app.js have set up a helper to compare equality: const hbs = require('hbs'); app.set('view engine', 'hbs'); hbs.registerHelper('ifEqual', (a, b, options) => { if (a === b) { return options.fn(this); } return options.inverse(this); }); My controller passes two variables to the view: res.render('my-view', { x: 3, y: 3, }); In my

Get helper in hbs when getting nested object

我怕爱的太早我们不能终老 提交于 2020-01-15 02:55:09
问题 suppose I have the following objects: image: { size: { l: { url: 'l.jpg', }, m: { url: 'm.jpg', }, s; { url: 's.jpg', } } }, mySize: 'm' If I want to get corresponding image url in my template, how should I do that? I tried: {{get image mySize 'url'}} but it does not work. I can get the url I want by typing like this: {{get (get image mySize) 'url')}} However this is a very unintuitive and ugly workaround. Is there any a better way? Thank you. 回答1: You need to use the concat helper along with

Logical OR/AND Handlebars.JS Helper, Multiple Arguments, First One Always Being Checked

最后都变了- 提交于 2020-01-06 06:52:14
问题 The following was proposed as a logical AND/OR multi-arg Handlebars.JS helper: Handlebars.registerHelper({ and: function () { return Array.prototype.slice.call(arguments).every(Boolean); }, or: function () { return Array.prototype.slice.call(arguments).some(Boolean); } }); Handlebars.js Else If This doesn't work for me because I need to call it as {{#if (or questionType 'STARTTIME' 'ENDTIME') }} {{#if (or questionType 'STARTTIME' 'ENDTIME' 'ARGUMENT3' 'ARGUMENT4') }} In other words, I support

Logical OR/AND Handlebars.JS Helper, Multiple Arguments, First One Always Being Checked

自闭症网瘾萝莉.ら 提交于 2020-01-06 06:51:39
问题 The following was proposed as a logical AND/OR multi-arg Handlebars.JS helper: Handlebars.registerHelper({ and: function () { return Array.prototype.slice.call(arguments).every(Boolean); }, or: function () { return Array.prototype.slice.call(arguments).some(Boolean); } }); Handlebars.js Else If This doesn't work for me because I need to call it as {{#if (or questionType 'STARTTIME' 'ENDTIME') }} {{#if (or questionType 'STARTTIME' 'ENDTIME' 'ARGUMENT3' 'ARGUMENT4') }} In other words, I support

Every nth row in handlebars shows weird behaviour

痴心易碎 提交于 2020-01-03 02:49:08
问题 {{#each orderData}} {{#everyOther @key 4 }} <div class="row"> {{/everyOther}} <div class="col-md-3"> <a class="aremove" href="/Channel/Details/{{getValueAtIndex ../channelIds @key}}" data-bypass> <div class="thumbnail"> <img src="{{getImageSourceChannel ../channelNames @key name}}" class=""> <div class="caption"> <p><b>{{getObjectAtIndex ../channelNames @key}}</b></p> <p class="">{{this.slices.3.count}} new orders</p> <p class="">{{this.slices.0.count}} back orders</p> </div> </div> </a> <

can't register handlebar helpers

浪尽此生 提交于 2019-12-25 01:28:07
问题 I'm having trouble registering a custom helper in handlebars. I've tried anything I could find but nothing works. here is what I have in app.js const express= require('express'); const exphbs = require('express-handlebars'); var socket = require('socket.io') const app=express(); const querystring = require('querystring'); var hbs = exphbs.create({ extname: '.hbs', defaultLayout: 'default', layoutsDir: './lib/templates/layouts', partialsDir: './lib/templates/partials', helpers: require(".

Taking input from inside handlebar template file (.hbs)

走远了吗. 提交于 2019-12-13 07:19:41
问题 How to take user input from a handlebar template .hbs file and send it to some other js function as argument I have tried so far: {{ # each content }} <tr role="row"> ..... <td <input name = "a" type="text" id="a_id" /> </td> <td> <button onclick="my_fn(a)"> SUBMIT </button> </td> </tr> {{/each}} For each data content there a row is created by this template .hbs file, in each row there is a field for taking user input and after entering text input a SUBMIT button is there in each row,clicking

How to Register custom handelbars helper in assemble 0.17.1

不打扰是莪最后的温柔 提交于 2019-12-11 05:52:09
问题 In my assemblefile.js I try to register a custom helper. The helper itself does work since i have it in use in a grunt project with assemble. assemble: { options: { helpers: ['./src/helper/custom-helper.js' ] } } In assemble 0.17.1 I tried it like this but it doesn´t work. Does anyone know how to do this? app.helpers('./src/helper/custom-helper.js'); custom-helper.js: module.exports.register = function (Handlebars, options, params) { Handlebars.registerHelper('section', function(name, options

Return html object from handlebars helpers

橙三吉。 提交于 2019-12-10 19:56:49
问题 I need to send an html object from handlebars helper as follow: Handlebars.registerHelper('helper', function () { //Create an input object var inp=$('<input type="text" name="name">'); //How to return 'inp' object without using Handlebars.SafeString return inp; }); I understand that I can return html string using ‘Handlebars.SafeString()’, however this is not useful to me I need to pass html object with some event assign to it. Is it possible? 回答1: As dandavis commented, using Handlebars you

TypeError: Handlebars.registerHelper is not a function

本秂侑毒 提交于 2019-12-03 08:51:54
问题 I am brand new to node and handlebars as of two days ago so bear with me. I am trying to use custom handlebars helpers but am not entirely sure where to put it. I keep getting "TypeError: Handlebars.registerHelper is not a function" Right now I have it in my server.js file. Not sure if this is correct. var express = require('express'); var app = express(); var Handlebars = require('express-handlebars'); app.engine('handlebars', Handlebars({ defaultLayout: 'main' })); app.set('view engine',