go-html-template

How to get rid of ZgotmplZ from html/template in Golang?

橙三吉。 提交于 2019-12-01 15:22:12
问题 I'm using Golang in backend. When I render the html using html/templates I'm getting ZgotmplZ for URL's. {{if .UserData.GitURL}} <li> <a href="{{.UserData.GitURL}}"> <i class="icon fa fa-github"></i> </a> </li> {{end}} I'm using string for GitURL in server side. This URL is https . When I looked for solutions some blog suggested to use safeURL . So I tried, {{if .UserData.GitURL}} <li> <a href="{{.UserData.GitURL | safeURL}}"> <i class="icon fa fa-github"></i> </a> </li> {{end}} But code didn

How to create a global variable and change in multiple places in golang html/template?

大城市里の小女人 提交于 2019-11-26 21:43:38
问题 I am creating a variable in html/template and and changing the value based on a condition. But the scope of the value stays only inside the if condition: {{if .UserData}} {{$currentUserId := .UserData.UserId}} [<a href="#ask_question">Inside {{$currentUserId}}</a>] {{else}} {{$currentUserId := 0}} {{end}} [<a href="#ask_question">outside {{$currentUserId}}</a>] Inside the if condition I am getting the correct value but outside it is 0 . How can I use the $currentUserId outside the condition?