(Golang) Gin template syntax

learning target:

  • Understand the basic features and common syntax of the Gin template engine, and master the method of using the template engine in the Gin framework.

  •  Module Specific Example

  • Login module example


Learning Content:

The Gin framework is a web framework written in the Go language that provides high-performance and flexible routers and middleware to accelerate the development of web applications. Gin also supports the use of several templating engines, including templates.

1. The Gin template uses the Go template engine as the underlying layer. The Gin template engine provides the following features:

1. Output

Like Go templates, use `{ {` and `}}`. output a value:


{ { name }}
 

2. Conditional statements


{ { if pipeline }}
    if the pipeline yields a true value
{ { else }}
    if the pipeline yields a false value
{ { end }}
 

3. Loop statement


{% for _, val := range arr %}
    { {index $val "field"}} // Take the "field" field of $val
    {

Guess you like

Origin blog.csdn.net/canduecho/article/details/130965921