Good day all. I've spent my whole node-red life using the function node. I finally decided to start cleaning up my flows code readability by using the template node for my html insted of foo += 'bar' in the function node.
Thank you for the documentation link. That all makes sense now.
I've created a function node before the template to pull the object key to the language_dictionary out.
All working well now.
If you are calling a function node, you may aswell create the template in the function.
You can use string templates to do this, notice the backticks (not quotes) and each variable is within ${}.
e.g.
msg.payload = `text
${msg.language_dictionary_object[msg.client_language].Username} some moretext
more text`
return msg;
Instead of a function node, you can use a change node to set msg.client_language_dictionary to the value of msg.language_dictionary_object[msg.client_language]
Using a template string in a function wouldn't be much of a gain in readability. The template node supports formatting and syntax highlighting for many formats. Personally, I'm using it for JSON and SQL queries mostly.
I think the combination of function -> template provides the best trade-off between readability and flexibility in this case.
LOL - I did not see/think of that. For those of us that have been using node-red from version 0.8.x you became one with the function node if you wanted to get anything hard done. Old habits die hard.
Not necessarily a bad thing. I often find that a chunk of logic is easily expressed in a function node that would take many nodes. If you are comfortable with JavaScript, this brings the best of both worlds (visual and code programming) together. Yet another strength for Node-RED, hurrah!