[{"data":1,"prerenderedAt":556},["ShallowReactive",2],{"node-red-\u002Fnode-red\u002Fcore-nodes\u002Ftemplate":3},{"id":4,"title":5,"body":6,"description":549,"extension":550,"meta":551,"navigation":100,"path":552,"seo":553,"stem":554,"__hash__":555},"nodeRed\u002Fnode-red\u002Fcore-nodes\u002Ftemplate.md","Node-RED - Template Node",{"type":7,"value":8,"toc":531},"minimark",[9,14,27,32,37,40,44,47,54,59,65,69,72,76,79,84,139,143,170,173,210,214,217,220,260,264,282,285,318,322,329,350,360,364,367,371,527],[10,11,13],"h1",{"id":12},"template","Template",[15,16,17,18,22,23,26],"p",{},"The \"Template\" node is used to create and manipulate text templates. For example for generating HTML, configuration files, our other text based strings.\nThe Template node allows you to generate dynamic content by injecting data into predefined templates using the Mustache templating language.\nWhen there's no need for dynamic templates, the ",[19,20,21],"code",{},"Format"," can be set to ",[19,24,25],{},"Plain Text",", which has a slight performance benefit.",[28,29,31],"h2",{"id":30},"how-the-template-node-works","How the Template node works",[33,34,36],"h3",{"id":35},"input-data","Input Data",[15,38,39],{},"You can connect the Template node to a source of data, such as an MQTT input, HTTP input, or any other node that provides data. This input data will be used to populate the template.",[33,41,43],{"id":42},"template-definition","Template Definition",[15,45,46],{},"In the Template node configuration, you define the template using text based formatting languages like HTML with the Mustache syntax.\nMustache is a simple and \"logic-less\" templating language that allows you to insert variables and expressions into your template.",[15,48,49,50,53],{},"For example, you can define a template like this: ",[19,51,52],{},"\u003Cp>Hello {{payload.name}}!\u003C\u002Fp>",".",[55,56],"render-flow",{":height":57,"flow":58},"200","W3siaWQiOiI5N2Q3NDJlZWMxY2I3ZGJmIiwidHlwZSI6ImluamVjdCIsInoiOiJhNmI3ZWRlMmUxM2ZjYmRmIiwibmFtZSI6IiIsInByb3BzIjpbeyJwIjoicGF5bG9hZCJ9LHsicCI6InRvcGljIiwidnQiOiJzdHIifV0sInJlcGVhdCI6IiIsImNyb250YWIiOiIiLCJvbmNlIjpmYWxzZSwib25jZURlbGF5IjowLjEsInRvcGljIjoiIiwicGF5bG9hZCI6IntcIm5hbWVcIjogXCJGbG93RnVzZVwifSIsInBheWxvYWRUeXBlIjoianNvbiIsIngiOjE4MCwieSI6NjAsIndpcmVzIjpbWyJjODVkNzBiNDFmMzc0ZjAyIl1dfSx7ImlkIjoiYzg1ZDcwYjQxZjM3NGYwMiIsInR5cGUiOiJ0ZW1wbGF0ZSIsInoiOiJhNmI3ZWRlMmUxM2ZjYmRmIiwibmFtZSI6IlRlbXBsYXRlIHVzaW5nIHBheWxvYWQubmFtZSIsImZpZWxkIjoicGF5bG9hZCIsImZpZWxkVHlwZSI6Im1zZyIsImZvcm1hdCI6ImhhbmRsZWJhcnMiLCJzeW50YXgiOiJtdXN0YWNoZSIsInRlbXBsYXRlIjoiPHA+SGVsbG8geyUgcmF3ICV9YHt7cGF5bG9hZC5uYW1lfX0heyUgZW5kcmF3ICV9PC9wPiIsIm91dHB1dCI6InN0ciIsIngiOjQ1MCwieSI6NjAsIndpcmVzIjpbWyI2ZGY3MjE1NDU5ZGZiMjQwIl1dfSx7ImlkIjoiNmRmNzIxNTQ1OWRmYjI0MCIsInR5cGUiOiJkZWJ1ZyIsInoiOiJhNmI3ZWRlMmUxM2ZjYmRmIiwibmFtZSI6IlByaW50IFwiPHA+SGVsbG8sIEZsb3dGdXNlITwvcD5cIiIsImFjdGl2ZSI6dHJ1ZSwidG9zaWRlYmFyIjp0cnVlLCJjb25zb2xlIjpmYWxzZSwidG9zdGF0dXMiOmZhbHNlLCJjb21wbGV0ZSI6InBheWxvYWQiLCJ0YXJnZXRUeXBlIjoibXNnIiwic3RhdHVzVmFsIjoiIiwic3RhdHVzVHlwZSI6ImF1dG8iLCJ4Ijo3NTAsInkiOjYwLCJ3aXJlcyI6W119XQ==",[15,60,61,62,53],{},"This example will output ",[19,63,64],{},"\u003Cp>Hello FlowFuse!\u003C\u002Fp>",[33,66,68],{"id":67},"output","Output",[15,70,71],{},"When the Template node receives input data, it processes the data and replaces Mustache placeholders with the corresponding values from the input data. The resulting HTML or text is then sent as output to the next node in the flow.",[28,73,75],{"id":74},"building-json","Building JSON",[15,77,78],{},"The template node can be configured to parse the result of the input and template\nas JSON, to further use the message as an object, not as string.",[80,81,83],"h4",{"id":82},"input-data-1","Input data",[85,86,91],"pre",{"className":87,"code":88,"language":89,"meta":90,"style":90},"language-js shiki shiki-themes github-light github-dark","\n{\n    payload: ['ACME', 1]\n}\n\n","js","",[19,92,93,102,109,133],{"__ignoreMap":90},[94,95,98],"span",{"class":96,"line":97},"line",1,[94,99,101],{"emptyLinePlaceholder":100},true,"\n",[94,103,105],{"class":96,"line":104},2,[94,106,108],{"class":107},"sVt8B","{\n",[94,110,112,116,119,123,126,130],{"class":96,"line":111},3,[94,113,115],{"class":114},"sScJk","    payload",[94,117,118],{"class":107},": [",[94,120,122],{"class":121},"sZZnC","'ACME'",[94,124,125],{"class":107},", ",[94,127,129],{"class":128},"sj4cs","1",[94,131,132],{"class":107},"]\n",[94,134,136],{"class":96,"line":135},4,[94,137,138],{"class":107},"}\n",[80,140,142],{"id":141},"template-node-configuration","Template node configuration",[144,145,146,158,164],"ul",{},[147,148,149,150],"li",{},"Template:\n",[85,151,156],{"className":152,"code":154,"language":155,"meta":90},[153],"language-text","\n{\n    \"product\": \"{{payload.0}}\",\n    \"version\": {{payload.1}}\n}\n\n","text",[19,157,154],{"__ignoreMap":90},[147,159,160,161],{},"Format: ",[19,162,163],{},"Mustache template",[147,165,166,167],{},"Output as: ",[19,168,169],{},"Parsed JSON",[80,171,68],{"id":172},"output-1",[85,174,178],{"className":175,"code":176,"language":177,"meta":90,"style":90},"language-json shiki shiki-themes github-light github-dark","\n{ \"product\": \"ACME\", \"version\": 1 }\n\n","json",[19,179,180,184],{"__ignoreMap":90},[94,181,182],{"class":96,"line":97},[94,183,101],{"emptyLinePlaceholder":100},[94,185,186,189,192,195,198,200,203,205,207],{"class":96,"line":104},[94,187,188],{"class":107},"{ ",[94,190,191],{"class":128},"\"product\"",[94,193,194],{"class":107},": ",[94,196,197],{"class":121},"\"ACME\"",[94,199,125],{"class":107},[94,201,202],{"class":128},"\"version\"",[94,204,194],{"class":107},[94,206,129],{"class":128},[94,208,209],{"class":107}," }\n",[33,211,213],{"id":212},"generating-javascript-object-from-yaml","Generating JavaScript object from YAML",[15,215,216],{},"Node-RED can also parse YAML",[80,218,83],{"id":219},"input-data-2",[85,221,223],{"className":87,"code":222,"language":89,"meta":90,"style":90},"\n{\n    topic: 'FlowFuse',\n    payload: 3000\n}\n\n",[19,224,225,229,233,246,255],{"__ignoreMap":90},[94,226,227],{"class":96,"line":97},[94,228,101],{"emptyLinePlaceholder":100},[94,230,231],{"class":96,"line":104},[94,232,108],{"class":107},[94,234,235,238,240,243],{"class":96,"line":111},[94,236,237],{"class":114},"    topic",[94,239,194],{"class":107},[94,241,242],{"class":121},"'FlowFuse'",[94,244,245],{"class":107},",\n",[94,247,248,250,252],{"class":96,"line":135},[94,249,115],{"class":114},[94,251,194],{"class":107},[94,253,254],{"class":128},"3000\n",[94,256,258],{"class":96,"line":257},5,[94,259,138],{"class":107},[80,261,263],{"id":262},"template-node-configuration-1","template node configuration",[144,265,266,274,278],{},[147,267,149,268],{},[85,269,272],{"className":270,"code":271,"language":155,"meta":90},[153],"\noptions:\n    title: {{topic}}\n    port: {{payload}}\n\n",[19,273,271],{"__ignoreMap":90},[147,275,160,276],{},[19,277,163],{},[147,279,166,280],{},[19,281,169],{},[80,283,68],{"id":284},"output-2",[85,286,288],{"className":175,"code":287,"language":177,"meta":90,"style":90},"\n{ \"title\": \"FlowFuse\", \"port\": 3000 }\n\n",[19,289,290,294],{"__ignoreMap":90},[94,291,292],{"class":96,"line":97},[94,293,101],{"emptyLinePlaceholder":100},[94,295,296,298,301,303,306,308,311,313,316],{"class":96,"line":104},[94,297,188],{"class":107},[94,299,300],{"class":128},"\"title\"",[94,302,194],{"class":107},[94,304,305],{"class":121},"\"FlowFuse\"",[94,307,125],{"class":107},[94,309,310],{"class":128},"\"port\"",[94,312,194],{"class":107},[94,314,315],{"class":128},"3000",[94,317,209],{"class":107},[28,319,321],{"id":320},"comments","Comments",[15,323,324,325,328],{},"When a template gets larger, it might be useful to add comments to the template\nwhich will not appear in the output. Comments work about the same as the normal\nsyntax, with a ",[19,326,327],{},"!"," after the opening curly brackets:",[85,330,334],{"className":331,"code":332,"language":333,"meta":90,"style":90},"language-mustache shiki shiki-themes github-light github-dark","\n{{! this won't show }}\nThis text will be in the output\n\n","mustache",[19,335,336,340,345],{"__ignoreMap":90},[94,337,338],{"class":96,"line":97},[94,339,101],{"emptyLinePlaceholder":100},[94,341,342],{"class":96,"line":104},[94,343,344],{},"{{! this won't show }}\n",[94,346,347],{"class":96,"line":111},[94,348,349],{},"This text will be in the output\n",[15,351,352,353,356,357,53],{},"Will result in ",[19,354,355],{},"This text will be in the output",". Note there's no empty line character ",[19,358,359],{},"\\n",[33,361,363],{"id":362},"mustache-partials","Mustache partials",[15,365,366],{},"Mustache by default supports partials to include. This is an unsupported feature\nin Node-RED.",[28,368,370],{"id":369},"node-documentation","Node Documentation",[372,373,376,379,380,379,384,379,418,379,422,379,433,379,437,379,449,452,455,458,461,464,467,489,503,514,517,521,524],"div",{"className":374},[375],"core-node-doc",[15,377,378],{},"Sets a property based on the provided template."," ",[33,381,383],{"id":382},"inputs","Inputs",[385,386,389,398,402,411],"dl",{"className":387},[388],"message-properties",[390,391,392,393],"dt",{},"msg ",[94,394,397],{"className":395},[396],"property-type","object",[399,400,401],"dd",{},"A msg object containing information to populate the template.",[390,403,406,407],{"className":404},[405],"optional","template ",[94,408,410],{"className":409},[396],"string",[399,412,413,414,417],{},"A template to be populated from ",[19,415,416],{},"msg.payload",". If not configured in the edit panel,\nthis can be set as a property of msg.",[33,419,421],{"id":420},"outputs","Outputs",[385,423,425,430],{"className":424},[388],[390,426,392,427],{},[94,428,397],{"className":429},[396],[399,431,432],{},"a msg with a property set by populating the configured template with properties from the incoming msg.",[33,434,436],{"id":435},"details","Details",[15,438,439,440,448],{},"By default this uses the ",[441,442,443],"i",{},[444,445,333],"a",{"href":446,"target":447},"http:\u002F\u002Fmustache.github.io\u002Fmustache.5.html","_blank","\nformat, but this can be switched off if required.",[15,450,451],{},"For example, when a template of:\n",[85,453,454],{},"Hello {{payload.name}}. Today is {{date}}",[15,456,457],{},"receives a message containing:\n",[85,459,460],{},"{\ndate: \"Monday\",\npayload: {\nname: \"Fred\"\n}\n}",[15,462,463],{},"The resulting property will be:\n",[85,465,466],{},"Hello Fred. Today is Monday",[15,468,469,470,473,474,477,478,481,482,473,485,488],{},"It is possible to use a property from the flow context or global context. Just use ",[19,471,472],{},"{{flow.name}}"," or\n",[19,475,476],{},"{{global.name}}",", or for persistable store ",[19,479,480],{},"store"," use ",[19,483,484],{},"{{flow[store].name}}",[19,486,487],{},"{{global[store].name}}",".\n",[15,490,491,495,496,498,499,502],{},[492,493,494],"b",{},"Note: ","By default, ",[441,497,333],{}," will escape any non-alphanumeric or HTML entities in the values it substitutes.\nTo prevent this, use ",[19,500,501],{},"{{{triple}}}"," braces.",[15,504,505,506,509,510,513],{},"If you need to use ",[19,507,508],{},"{{ }}"," within your content, you can change the characters\nused to mark the templated sections. For example, to use ",[19,511,512],{},"[[ ]]","\ninstead, add the following line to the top of the template:",[85,515,516],{},"{{=[[ ]]=}}",[80,518,520],{"id":519},"using-environment-variables","Using environment variables",[15,522,523],{},"The template node can access environment variables using the syntax:",[85,525,526],{},"My favourite colour is {{env.COLOUR}}.",[528,529,530],"style",{},"html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":90,"searchDepth":104,"depth":104,"links":532},[533,538,541,544],{"id":30,"depth":104,"text":31,"children":534},[535,536,537],{"id":35,"depth":111,"text":36},{"id":42,"depth":111,"text":43},{"id":67,"depth":111,"text":68},{"id":74,"depth":104,"text":75,"children":539},[540],{"id":212,"depth":111,"text":213},{"id":320,"depth":104,"text":321,"children":542},[543],{"id":362,"depth":111,"text":363},{"id":369,"depth":104,"text":370,"children":545},[546,547,548],{"id":382,"depth":111,"text":383},{"id":420,"depth":111,"text":421},{"id":435,"depth":111,"text":436},"The \"Template\" node is used to create and manipulate text templates. For example for generating HTML, configuration files, our other text based strings.\nThe Template node allows you to generate dynamic content by injecting data into predefined templates using the Mustache templating language.\nWhen there's no need for dynamic templates, the Format can be set to Plain Text, which has a slight performance benefit.","md",{},"\u002Fnode-red\u002Fcore-nodes\u002Ftemplate",{"title":5,"description":549},"node-red\u002Fcore-nodes\u002Ftemplate","3MbAmcZE6kK-l26EGlUnMpNR60tP_Eokz4u6V8Af8Vw",1780070556295]