Adding "id" to <h2> tag in HTML node to generate HTML template not rendering the "id"

Hi there.
I am trying to add an IDs to my <h2> in the HTML node, Generate HTML template.

{{ $input.all().map(item => <h2 id="${item.json.title.trim().toLowerCase().replace(/[\s:]+/g, '-').replace(/[^a-z0-9\-]/g, '')}">${item.json.title}</h2><p>${item.json.message.content}</p> ).join(‘’) }}`

When I change “id” to “class” it will create a class in my h2 tag. But with “id” its not working, it willl only show the <h2> without id=“xyz”.
Is “id” maybe kinda like a protected term, that I cannot use in js expressions? And if so, how can I still get the “id” output?

Thank you!

  • n8n version: 1.33.1
  • Database : SQLite
  • Running n8n via:Docker
  • n8n EXECUTIONS_PROCESS setting: own
  • Operating system: Win 11, n8n on Ubuntu Hetzner

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Good morning.
Okay, so I realized, its only the preview in n8n, that does not render the id.
I used to inspect the preview in n8n, to see if the id is available and it seems, that it will not be recognized.
Than I checked the JSON output and tadaa, the ID actually IS there… should have done that before asking here ;).

Anyway, just in case, someone else would be wondering, why the id is not showing in the preview.

Have a nice day everyone! :slight_smile:

2 Likes

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