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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:04:38+00:00 2026-06-01T22:04:38+00:00

Using Mustache js (a logic less templating) is there a way i can achieve

  • 0

Using Mustache js (a logic less templating) is there a way i can achieve switch case? this i need because a class is assigned to dom element based on the value for example:

switch(tasks.Count)
{
   case 0:
       element.Class = "no-tasks";
    break;
   case 1:
       element.Class = "one-tasks";
   break;
.
.
.
}

that’s the code i got now, how do i transform it to template( I Believe having methods on model being rendered is the one option) But adding methods to determine which class to use is an overkill and besides that is going to pollute my model to a swamp!!

  • I ask this because i am using Nustache a port of MustacheJs to C#, .NET to render nested model.Anything that applies to Mustache also applies to Nustache
  • 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-01T22:04:41+00:00Added an answer on June 1, 2026 at 10:04 pm

    There’s a few ways to do this.

    In Javascript, if Mustache encounters a function in a value, it will call it using the enclosed text as the only argument.

    var data = {
        foo: function(text) { return '<b>' + text + '</b>'; }
    }
    

    mustache

    {{#foo}}
       HI I LIKE FISH, thanks.
    {{/foo}}
    

    outputs

    <b>HI I LIKE FISH, thanks.</b>
    

    Search for “lambda” in the mustache docs.

    Another way to do it is do a falsey/truthy check.

    data

    { foo: true }
    

    mustache

    {{#foo}}
      output this if true.
    {{/foo}}
    {{^foo}}
      output if false
    {{/foo}}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
I am using this data here: http://pastie.org/3231052 - How can I display the key
This is really weird. Its my first time with using the mustache library and
I'm using backbone's underscore templating engine with the mustache formatting patterns. I have already
I use underscore.js for HTML Templating, set to use mustache syntax, like this: {{
I'm using Backbone along with Mustache, how can I detect when a view is
I'm using Mustache in Rails 3 with this gem and I'm hitting a roadblock
I've decided that I will be using Mustache for our templating engine for our
I am using the Mustache templating library and trying to generate a comma separated
Is there any documentation on Mustache best practices when using on the server (with

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.