Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

216
Views
golang, how to disable autoscape in templates

I have a template which is included from several other templates. I am passing in some data, and I want to dynamically create some javascript in each page.

I have the following in each template

<canvas id="{{.Id}}"></canvas>

<script type='application/ld+json'>
    const {{ .Id }} = new Chart(document.getElementById({{.Id}}) 
    ...

I expect to create something like this

<canvas id="someName"></canvas>

<script type='application/ld+json'>
    const someName = new Chart(document.getElementById(someName) 
    ...

but instead, I get this

<canvas id="someName"></canvas>

<script type='application/ld+json'>
    const "someName" = new Chart(document.getElementById("someName") 
    ...

After looking this up, apparently golang makes an attempt to add characters to my string out on my-behalf when it detects the 'script' tag. Obviously the true context of what I am doing is not understood by this feature. Is there any way to get around this 'helper feature', or even better, a way to disable this completely?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!