The difference between template syntax if and with

Time:2021-9-15

If keyword

The syntax is as follows

{{if pipeline}} T1 {{end}}
{{if pipeline}} T1 {{else}} T0 {{end}}
{{if pipeline}} T1 {{else if pipeline}} T0 {{end}}

The pipeline is the judgment condition, and the direct result is similar to if in go language

With keyword

The syntax is as follows

{{ with pipeline }} T1 {{ end }}
{{ with pipeline }} T1 {{ else }} T0 {{ end }}

The pipeline is the judgment condition, which is similar to the if keyword, but the difference I have learned is that if the pipeline is empty, no output will be generated, otherwise. Will be set as the value of pipeline and T1 will be executed. Do not modify the external. Otherwise, execute t0 and pay attention not to modify.

This work adoptsCC agreement, reprint must indicate the author and the link to this article

Recommended Today

Monkey patch monkey patch programming method and its application in Ruby

What ismonkey patch (Monkey Patch)? In a dynamic language, functions are added and changed without modifying the source code. Purpose of using monkey patch:1. Additional function2. Function change3. Fix program errors4. Add a hook to execute some other processing while executing a method, such as printing logs, realizing AOP, etc,5. Cache, when the amount of […]