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 9253963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:20:56+00:00 2026-06-18T11:20:56+00:00

I have the follow data multipleTypes = [ {type: radio, label: Cool people names,option:

  • 0

I have the follow data

multipleTypes = [
        {"type": "radio", "label": "Cool people names","option": ["Ralgar", "Mozzy"]},
        {"type": "checkbox", "label": "Cool phones", "option": ["android", "iphone"]}
        {"type": "radio", "label": "Cool pets", "option": ["monster", "moose"]},
        {"type": "checkbox", "label": "Cool places", "option": ["bar", "undercovers", "moon"]},
    ]

Here are the templates

<script id="checkbox-template" type="text/x-handlebars-template">
    <fieldset>
        <legend>{{label}}</legend>
        {{#each option}}
            <label for="regularCheckbox">
                <input type="checkbox" id="regularCheckbox" value="checkbox 1">
                <span>{{this}}</span>
            </label>
        {{/each}}
    </fieldset>
</script>
<script id="radio-template" type="text/x-handlebars-template">
    <fieldset>
        <legend>{{label}}</legend>
        {{#each option}}
            <label for="regularRadio">
                <input type="radio" name="radios" id="regularRadio" value="radio 1">
                <span>{{this}}</span>
            </label>
        {{/each}}
    </fieldset>
</script>

I’m trying to go down the list of objects and render the template based on the type attribute. Is this possible?

If else within the template didn’t work out too well.

  • 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-06-18T11:20:57+00:00Added an answer on June 18, 2026 at 11:20 am

    Handlebars doesn’t have a way of testing values, but you could use a helper like Comparison block helper for handlebars templates to test the type property and render a particular block of HTML:

    {{#compare type "radio"}}
    Radio HTML
    {{/compare}}
    {{#compare type "checkbox"}}
    Checkbox HTML
    {{/compare}}
    

    However, you might want to consider transforming your data. If all inputs are either checkboxes or radios, perhaps use a boolean radio property for items that use the radio buttons. Your data would now look like:

    multipleTypes = [
        {"radio": true, "label": "Cool people names","option": ["Ralgar", "Mozzy"]},
        {"radio": false, "label": "Cool phones", "option": ["android", "iphone"]}
        {"radio": true, "label": "Cool pets", "option": ["monster", "moose"]},
        {"radio": false, "label": "Cool places", "option": ["bar", "undercovers", "moon"]},
    ]
    

    Then you can use if/else:

    {{#if radio}}
    Radio HTML
    {{else}}
    Checkbox HTML
    {{/if}}
    

    Or, just do the template selection in the calling code:

    var templates = {
      'radio': Handlebars.compile($('#radio-template').html()),
      'checkbox': Handlebars.compile($('checkbox-template').html())
    };
    multipleTypes.forEach(function(item) {
      var rendered = templates[item.type](item);
      // Do something with rendered output ...
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the follow VBA code and it returns a ' data type mismatch
I have 8823 data points with x,y coordinates. I'm trying to follow the answer
I have a ContentPane defined as follows: <div id=searchResultsContentPane data-dojo-type=dijit.layout.ContentPane data-dojo-props='splitter:false, region:center'></div> I am
I have the follow T-SQL to update a table with test data: UPDATE SomeTable
I have the follow data returned via JSON {rows:[{Date:07/10/2011,Value:1206,Action:Drink}, {Date:07/11/2011,Value:2288,Action:Pie}, {Date:07/12/2011,Value:1070,Action:Drink}, {Date:07/13/2011,Value:1535,Action:Beer}, {Date:07/14/2011,Value:1721,Action:Drink}], page:1,total:1,records:5}
I have the follow query: SELECT table1.data AS table1_data, table2.data AS table2_data, table3.data AS
I have the follow bit of Javascript: $.ajax({ url: /Web/WebServices/Operation.svc/SetScope, type: POST, contentType: application/json;
In my model I have the follow query: function myquerydata() { $data = array();
<?php if (in_array($key,$following)){ echo ' <form id=follow action= action.php method=GET data-theme=a> <input type=hidden name=id
I have a column that has a string in it as follow Data black83736

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.