This is a creation in Article, where the information may have evolved or changed.
Golang's Text/template package is inconvenient when used, especially when it comes to logical judgments. After testing, it was found that the following wording is correct. 1.2.1 Environment is not a problem!
Related information: Https://gowalker.org/text/template.
EQ is a function.
Package Mainimport "text/template" import "OS" Func Main () {type Inventory struct {Material stringcount int}sweaters: = inventory{"Axe", 0}html: = ' "Test"). Parse ("{{. Count}} items are made of {{. Material}} "{{$a: =. count}}{{$b: = 17}}{{$c: = +}} {{if EQ . Count $b}}oo{{else}}xx{{end}} ' Tmpl, err: = template. New ("Test"). Parse (HTML) if err! = Nil {panic (err)}err = Tmpl. Execute (OS. Stdout, sweaters) if err! = Nil {panic (err)}}
{len.} Statistics | print}}{{$le: = Len. STATISTICS}}{{IF eq $le 0}} is 0 {{else}} not 0 {{end}}
If/else and OR, the use of EQ functions
{{else if or (eq $e. Status-2) (eq $e. Status-3)}}
{{with and ($et: =. Extension) ($ch: =. Changelog)}}
{{Range $e: = $ch}}
...
{{$et.} Name}} {{$e. Version}}
{{End}}
{{End}}
Add:
There is a variable, $, that's can use to solve your problem. From the Text/template docs: "When execution begins, $ was set to the data argument passed to Execute, that's, to the star Ting value of dot. " In your case:
{{with ($ch: =. Changelog)}}
{{Range $e: = $ch}}
<!--begin Ch-->
<span>
{{$e. Createtime}} HTML1
</span>
{{with ($u: = $. User)}}
<a href= "/xxx?cid={{$e. CID}}" >html2
</a>
{{End}}
<!--end Ch-->
{{End}}
{{End}}
The supported syntax is small, but fully sufficient!