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
    • 272
    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:-

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


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

    {{check-equality 1 10}} // Returns: false
    {{check-equality 10 10}} // Returns: true
    {{check-equality 20 10}} // Returns: false
    {{check-equality 20 20}} // Returns: true


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

    {{#if (check-equality 1 10)}}
        both numbers are equal
    {{else}}
        both are unequal
    {{/if}}

    Result:

    both are unequal    

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: