Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7574925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:33:28+00:00 2026-05-30T16:33:28+00:00

I have the following data that I am trying to feed into a Handlebar

  • 0

I have the following data that I am trying to feed into a Handlebar template

{
    "set-group": [
        {
            "label": "Source Data",
            "type": "select",
            "options": [
                {
                    "value": "Default Selections"
                },
                {
                    "value": "Other Selections"
                }
            ]
        },
        {
            "label": "Scale",
            "type": "radio",
            "options": [
                {
                    "value": "log",
                    "label": "Log",
                    "groupname": "group2"
                },
                {
                    "value": "linear",
                    "label": "Linear",
                    "groupname": "group2"
                }
            ]
        }
    ]
}

I created and registered 2 Partials, one that templates “selects” form elements and one that templates “radio” inputs. I cannot know what type of form element will be in the data so I need some sort of helper that checks if type == select and applies the appropriate partial for the select. I am having trouble with creating such a helper.

I was thinking of replacing type=select in the data to just select=true and just check for true/false using the if/else helper but I would rather keep the format standardized

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T16:33:29+00:00Added an answer on May 30, 2026 at 4:33 pm

    I ended up using this helper

    // Comparison Helper for handlebars.js
    // Pass in two values that you want and specify what the operator should be
    // e.g. {{#compare val1 val2 operator="=="}}{{/compare}}
    
    Handlebars.registerHelper('compare', function(lvalue, rvalue, options) {
    
        if (arguments.length < 3)
            throw new Error("Handlerbars Helper 'compare' needs 2 parameters");
    
        operator = options.hash.operator || "==";
    
        var operators = {
            '==':       function(l,r) { return l == r; },
            '===':      function(l,r) { return l === r; },
            '!=':       function(l,r) { return l != r; },
            '<':        function(l,r) { return l < r; },
            '>':        function(l,r) { return l > r; },
            '<=':       function(l,r) { return l <= r; },
            '>=':       function(l,r) { return l >= r; },
            'typeof':   function(l,r) { return typeof l == r; }
        }
    
        if (!operators[operator])
            throw new Error("Handlerbars Helper 'compare' doesn't know the operator "+operator);
    
        var result = operators[operator](lvalue,rvalue);
    
        if( result ) {
            return options.fn(this);
        } else {
            return options.inverse(this);
        }
      });
    

    Source: http://doginthehat.com.au/2012/02/comparison-block-helper-for-handlebars-templates/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following data set that I am trying to plot with ggplot2,
I have the following connection string: Data Source=localhost\\SQLEXPRESS; , it complains that '' is
So I have the following data that represets the hour and quarter hour with
If I have the following data that is printed seperated by tabs using print
I have the following data model: I am writing a WCF service that needs
I have a column that has the following data: PersonId=315618 LetterId=43 MailingGroupId=1 EntityId=551723 trackedObjectId=9538
I have this following setup, a textarea named with some data in it that
I have multiple data entries that contain the following information: id_number name1 date name2
I have the following static method that prints the data imported from a 40.000
I have a data file that looks like the following example. I've added '%'

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.