Custom template tags are specific to a draft. By calling draft.setTemplateTag
you are setting a tag value for the current draft.
The “New Draft with Template” action creates a new draft, held in the d
var in the script, and runs it through the template engine. It is a different draft, so does not contain the new tag value you assigned to draft
- hopefully that makes some sense.
Several ways to solve this problem. Assuming you have modified the “New Draft with Template” action to contain an additional script above (I guess in a separate step?), you could change the end of that script as follows:
let temperature = "No temperature retrieved"; // default value
if (data) {
temperature = data.main.temp + '°C'; // remove `let`!
alert(temperature);
}
Then in the “new draft” script from the template action, look for this section and add the indicated line:
let d = Draft.create();
for (let tag of template.tags) {
if (tag != "template") {
d.addTag(tag);
}
}
// BEGIN ADD
d.setTemplateTag("temperature", temperature);
// END ADD
d.content = d.processTemplate(template.content);
d.update();
That will set the template value on the newly created draft and it will work.