mardi 5 novembre 2019

Go template: how can I inject a if statement in an HTML attribute?

I'm trying to create a gohtml (Go 1.13) with a context .

I've managed to display context variables as div values, but I can't find the right way to put context variables inside HTML attributes.

For instance, this code works :

 
<a href="/"></a>

But this does not seem to work :

<a href=" ">

I' ve tried different syntaxes :

  • single quotes :
<a href=' '>
  • double quotes in front of the conditional statement:
<a href="" >
  • double quotes around :
<a href=" ">

I've read https://golang.org/pkg/html/template/ but didn't find any clue in it.

Thanks for your help !

Aucun commentaire:

Enregistrer un commentaire