# Mustache statement not working

**URL:** <https://discourse.nodered.org/t/mustache-statement-not-working/76556>\
**Category:** General\
**Created:** [14 March 2023 15:41 UTC](https://discourse.nodered.org/t/mustache-statement-not-working/76556 "2023-03-14T15:41:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Meloman](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/meloman/32/96137_2.png) [@Meloman](https://discourse.nodered.org/u/Meloman)\
**Post date:** [14 March 2023 15:41 UTC](https://discourse.nodered.org/t/mustache-statement-not-working/76556/1 "2023-03-14T15:41:28Z")

</div>

Hi,

I have this code, and it's not working, could someone help me please ?  
Not sure Mustache is 100% supported by Node-Red or maybe it's a simplified version without all statements !?

```auto
[{"id":"55271cabcb3274a6","type":"http in","z":"1418dae22be032be","name":"","url":"/job/add","method":"get","upload":false,"swaggerDoc":"","x":850,"y":1380,"wires":[["5337cd7e2fce6e88"]]},{"id":"5337cd7e2fce6e88","type":"function","z":"1418dae22be032be","name":"Prepare vars","func":"//msg.payload = global.get('conf');\nmsg.payload = {\n containers :{\n 1: {\n checked : 1\n },\n 2: {\n checked : 1\n },\n 3: {\n checked : 0\n },\n 4: {\n checked : 0\n }, \n 5: {\n checked : 0\n },\n 6: {\n checked : 0\n }, \n 7: {\n checked : 0\n }\n }\n};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1030,"y":1380,"wires":[["3dd281899b8e760b","4922c9bcdc6ddb06"]]},{"id":"3dd281899b8e760b","type":"template","z":"1418dae22be032be","name":"modal - ajouter un job","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<div class=\"modal-dialog modal-lg\">\n <div class=\"modal-content\">\n\n\t\t<div class=\"modal-header\">\n\t\t\t<h5 class=\"modal-title\" id=\"exampleModalLabel\">title</h5>\n\t\t\t<button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"Annuler\"></button>\n\t\t</div>\n\t\t\n\t\t<div class=\"modal-body\">\n\t\t\t\n\t\t\t<form id=\"form-job-add\" method=\"post\" action=\"/job/add\">\n\t\t\t\t\n\t\t\t\t<input type=\"hidden\" name=\"ctrl\" value=\"job-edit\" />\n\t\t\t\t<input type=\"hidden\" name=\"cmd\" value=\"add\" />\n\t\t\t\t\n\t\t\t\t<div class=\"tab-pane container fade show active\" id=\"general\" role=\"tabpanel\" aria-labelledby=\"description-tab\">\n\t\t\t\t\n\t\t\t\t\t<div class=\"row mt-3\">\n\t\t\t\t\t\t<div class=\"col-12\">\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t<div class=\"row fabrication_order\">\n\t\t\t\t\t\t\t\t<table class=\"table-responsive table-sm table-fabrication_order_add\">\n\t\t\t\t\t\t\t\t\t<thead>\n\t\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t<th scope=\"col\">Containers(s)</th>\n\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t</thead>\n\t\t\t\t\t\t\t\t\t<tbody>\n\t\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t<td class=\"container pt3s\">\n\t\t\t\t\t\t\t\t\t\t\t\t{{#containers}}\n\t\t\t\t\t\t\t\t\t\t\t\t\t{{#uuid}}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input type=\"checkbox\" id=\"{{.}}\" {{#checked}}checked{{/checked}} name=\"fabrication_order[][container][]\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<label for=\"{{.}}\">{{@index}}</label>\n\t\t\t\t\t\t\t\t\t\t\t\t\t{{/uuid}}\n\t\t\t\t\t\t\t\t\t\t\t\t{{/containers}}\n\t\t\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t</tbody>\n\t\t\t\t\t\t\t\t</table>\n\t\t\t\t\t\t\t</div>\n\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\n\t\t\t\t</div>\t\t\n\n\t\t\t</form>\n\t\t\t\n\t\t</div>\n\t\t\n\t\t<div class=\"modal-footer\">\n\t\t\t<button type=\"button\" id=\"btn-cancel\" class=\"btn btn-secondary\" data-bs-dismiss=\"modal\">Fermer</button>\n\t\t\t<button type=\"button\" id=\"btn-save\" class=\"btn btn-primary\">Enregistrer</button>\n\t\t</div>\n\t\t\n </div>\n</div>","output":"str","x":1260,"y":1380,"wires":[["665fc973cea60842"]]},{"id":"4922c9bcdc6ddb06","type":"debug","z":"1418dae22be032be","name":"debug 17","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1220,"y":1440,"wires":[]},{"id":"665fc973cea60842","type":"http response","z":"1418dae22be032be","name":"Send HTML","statusCode":"","headers":{},"x":1470,"y":1380,"wires":[]}]

```

Actually, I try to populate 7 checkboxes and auto-check them in a Mustache Template. I precise it's not used with Dashboard but with /get /post from ajax calls on html pages I control myself.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [14 March 2023 16:16 UTC](https://discourse.nodered.org/t/mustache-statement-not-working/76556/2 "2023-03-14T16:16:25Z")

</div>

It would be a lot easier for people to help if you shared example input data and the mustache code. Not everyone is in a position to keep installing flows in order to help people.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [14 March 2023 16:46 UTC](https://discourse.nodered.org/t/mustache-statement-not-working/76556/3 "2023-03-14T16:46:27Z")

</div>

Mustache likes arrays when looping, not objects, so your data would be best an array of objects.  
Your data object(change to array) is also in payload.container.  
$index does not work in mustache, i believe it is handlebar syntax.  
Best to have you id, names, index all in the array objects.  
e.g.  
payload

```auto
{
    "containers": [
        {
            "checked": 1,
            "id": 1
        },
        {
            "checked": 1,
            "id": 2
        },
        {
            "checked": 0,
            "id": 3
        }
    ]
}

```

Then the mustache would be

```auto
{{#payload.containers}}
    <input type="checkbox" id="{{id}}" {{#checked}}checked{{/checked}} name="fabrication_order[][container][]">
	<label for="{{id}}">{{id}}</label>
{{/payload.containers}}

```

Output

```auto
<input type="checkbox" id="1" checked name="fabrication_order[][container][]">
<label for="1">1</label>.......................

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [13 May 2023 16:47 UTC](https://discourse.nodered.org/t/mustache-statement-not-working/76556/4 "2023-05-13T16:47:17Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
