Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to create a custom helper in ember js, handlebar and ghost node.js

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 804
    Comment on it

    Sometimes, you may have repeated HTML on your handlebars template. In those cases, you can create and register a new helper, that can be invoked from hbs templeate.

    Gost: Ghost it a blogging platform developer on the top of express framework of nodejs.

    EmberJs: Ember js is a javascript framework, same as angular.js.

    So, here I am going to tell you how to create a helper in ghost ember and handlebar.

    check-equality.js:

    Create a new file "check-equality" and place it inside "/core/client/app/helper/".

    Code:-

    1. import {helper} from 'ember-helper';
    2.  
    3. export default helper(function (value) { //Value is an array: [1,10]
    4. var actual = value[0];
    5. var expected = value[1];
    6. return actual === expected;
    7. });


    How to use the check-equality helper in handlebars template (edit.hbs) file:

    1. {{check-equality 1 10}} // Returns: false
    2. {{check-equality 10 10}} // Returns: true
    3. {{check-equality 20 10}} // Returns: false
    4. {{check-equality 20 20}} // Returns: true


    It can also be used to check certain condition for example:

    1. {{#if (check-equality 1 10)}}
    2. both numbers are equal
    3. {{else}}
    4. both are unequal
    5. {{/if}}

    Result:

    both are unequal    

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: