Check with mustache js if parameter is a specific value

后端 未结 2 437
花落未央
花落未央 2020-12-14 15:50

Is it possible to check in mustache js for a specific value like {{name}} == \"James\" ?

DATA:

json: {
    name: \"James\"
}


        
相关标签:
2条回答
  • 2020-12-14 16:22

    No. The idea behind mustache is that it is a logic-less templating syntax. So, no, such a logic is not possible.

    We call it "logic-less" because there are no if statements, else clauses, or for loops. Instead there are only tags. Some tags are replaced with a value, some nothing, and others a series of values. https://github.com/janl/mustache.js

    0 讨论(0)
  • 2020-12-14 16:35

    Although the question was answered I just have one thing to add (and it's a bit too long for a comment). As Harri pointed, such logic is indeed not possible. However, a cool thing I use quite often with Mustache is testing for true and false. When you are "constructing" Mustache json object, prepare the logic you'll be needing in the template. For instance in your case, if the object is as follows:

    json: {
        name: "James",
        isJames: true
    }
    

    Then in the template you can have:

    {{#isJames}}
        //the name is James
    {{/isJames}}
    
    {{^isJames}}
        //the name is NOT James
    {{/isJames}}
    
    0 讨论(0)
提交回复
热议问题