github.com/coveo/gotemplate@v2.7.7+incompatible/docs/doc_test/templates.md (about)

     1  {% include navigation.html %}
     2  {% raw %}
     3  # Templates
     4  
     5  ## Defining templates
     6  
     7  ### Razor
     8  ```
     9  @-define("razorTemplate")
    10    This is a template with a variable here: @.var1  
    11    For each item in var2:  
    12    @-for ($item := .var2)
    13      Print it: @$item  
    14    @-end for
    15  @-end define
    16  ```
    17  
    18  ### Gotemplate
    19  ```
    20  {{- define "goTemplate" }}
    21    This is a template with a variable here: {{ get . "var1" }}
    22    For each item in var2:
    23    {{- range $item := .var2 }}
    24      Print it: {{ $item }}
    25    {{- end }}
    26  {{- end }}
    27  ```
    28  
    29  ## Using templates
    30  
    31  ```
    32    @values := data(`{"var1": "Test", "var2": ["Test1", "Test2"]}`)
    33  ```
    34  
    35  | Razor | Gotemplate
    36  | ---   | ---
    37  | ```@template("razorTemplate", values)``` | ```{{ template "goTemplate" .values }}```
    38  
    39  ### Result
    40  
    41  ```
    42    This is a template with a variable here: Test
    43    For each item in var2:
    44      Print it: Test1
    45      Print it: Test2
    46  ```
    47  
    48  {% endraw %}