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

  • Home
  • SEARCH
  • 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 8717013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:13:04+00:00 2026-06-13T06:13:04+00:00

This is the JSON array: { profile: [ { ID: 343, gender: female, from:

  • 0

This is the JSON array:

{
"profile": [
    {
        "ID": 343,
        "gender": "female",
        "from": "Olivia"
    },
    {
        "ID": 4543,
        "gender": "female",
        "from": "Meagen"
    },
    {
        "ID": 787,
        "gender": "male",
        "from": "Aaron"
    }
]
}

This works and it outputs all the objects in the array…

{{#profile}}

{{from}} {{gender}}

{{/profile}}

Output will look like…

Olivia female
Meagen female
Aaron male

But my goal is to only loop those that have a gender equal to female. Something like…

{{#profile gender="female"}}

{{from}} {{gender}}

{{/profile}}

…and get the output to look like…

Olivia female
Meagen female

I’ve been struggling trying to find an answer for a few days. Am I missing something or am I way off track?

  • 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-13T06:13:05+00:00Added an answer on June 13, 2026 at 6:13 am

    I see two options:

    1. Filter the data before handing it Handlebars.
    2. Use a custom helper to deal with the logic inside your template.

    The first one is pretty straight forward.

    The second depends on how you want to do it. You could add an “if equal” helper:

    Handlebars.registerHelper('if_eq', function(a, b, block) {
        return a == b
             ? block(this)
             : block.inverse(this);
    });
    

    and do this in your template:

    {{#profile}}
        {{#if_eq gender "female"}}
            {{from}} {{gender}}
        {{/if_eq}}
    {{/profile}}
    

    Demo: http://jsfiddle.net/ambiguous/NnH83/

    Or you could write your own iterator in various ways:

    Handlebars.registerHelper('each_female', function(list, opts) {
        var i, result = '';
        for(i = 0; i < list.length; ++i)
            if(list[i].gender == 'female')
                result = result + opts.fn(list[i]);
        return result;
    });
    
    {{#each_female profile}}
        {{from}} {{gender}}
    {{/each_female}}
    

    Or a bit more general:

    Handlebars.registerHelper('each_when', function(list, k, v, opts) {
        console.log(arguments);
        var i, result = '';
        for(i = 0; i < list.length; ++i)
            if(list[i][k] == v)
                result = result + opts.fn(list[i]);
        return result;
    });
    
    {{#each_when profile "gender" "female"}}
        {{from}} {{gender}}
    {{/each_when}}
    

    Demos: http://jsfiddle.net/ambiguous/E4jTs/, http://jsfiddle.net/ambiguous/AkZxN/

    See the fine manual on Hash Arguments if you want something closer to your proposed syntax.

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

Sidebar

Related Questions

I'm trying to get objects from a multi-level JSON array. This is the an
I have this array of JSON: [{'pk': 4L, 'model': u'logic.member', 'fields': {'profile': 3L, 'name':
How can i convert this JSON array: This is a serialized JSON array 2012-06-18
I am trying to deserialize this JSON array into my android project. [{Name:Ban,Price:1},{Name:Banana,Price:1},{Name:chicken,Price:14},{Name:pizza,Price:16},{Name:slice,Price:1}] I
i have this JSON: var projects_array = new Array( {name:myName1, id:myid1, index:1}, {name:myName2, id:myid2,
I've json array like this: {GetReportResult: [ {bulan:4,total:2448,type:CHEESE1K,uang:8847823}, {bulan:4,total:572476,type:ESL,uang:5863408410}, {bulan:4,total:46008,type:ESL500ML,uang:234498301}, {bulan:5,total:5703,type:CHEESE1K,uang:134929306}, {bulan:5,total:648663,type:ESL,uang:6645764498}, {bulan:5,total:51958,type:WHP,uang:631994613}, {bulan:6,total:6190,type:CHEESE1K,uang:104527773},
I have a JSON array like this: { forum:[ { id:1, created:2010-03-19 , updated:2010-03-19
How do I iterate through this json message's nested array(i.e. orders) with jquery? [{Type:X,Symbol:AAP,BidPrice:17.0,
I'm having some issues to deserialize a Json array that follows this format: [
I have some troubles mapping a JSON Array to RestKit. This is what the

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.