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

     1  {% include navigation.html %}
     2  {% raw %}
     3  # Data manipulation
     4  
     5  Using a data file with the following content in a format that doesn't follow a standard.
     6  ```!Data
     7  IntegerValue = 1
     8  FloatValue = 1.23
     9  StringValue = "Foo bar"
    10  EquationResult = @(2 + 2 * 3 ** 6)
    11  ListValue = ["value1", "value2"]
    12  DictValue = {"key1": "value1", "key2": "value2"}
    13  ```
    14  
    15  ## toYaml
    16  
    17  | Razor | Gotemplate
    18  | ---   | ---
    19  | ```@toYaml(data("!Data"))``` | ```{{ toYaml (data "!Data") }}```
    20  
    21  ```
    22  DictValue:
    23    key1: value1
    24    key2: value2
    25  EquationResult: 46658
    26  FloatValue: 1.23
    27  IntegerValue: 1
    28  ListValue:
    29  - value1
    30  - value2
    31  StringValue: Foo bar
    32  ```
    33  
    34  ## toJson
    35  
    36  | Razor | Gotemplate
    37  | ---   | ---
    38  | ```@toPrettyJson(data("!Data"))``` | ```{{ toPrettyJson (data "!Data") }}```
    39  
    40  ```
    41  {
    42    "DictValue": {
    43      "key1": "value1",
    44      "key2": "value2"
    45    },
    46    "EquationResult": 46658,
    47    "FloatValue": 1.23,
    48    "IntegerValue": 1,
    49    "ListValue": [
    50      "value1",
    51      "value2"
    52    ],
    53    "StringValue": "Foo bar"
    54  }
    55  ```
    56  
    57  ## toHcl
    58  
    59  | Razor | Gotemplate
    60  | ---   | ---
    61  | ```@toPrettyHcl(data("!Data"))``` | ```{{ toPrettyHcl (data "!Data") }}```
    62  
    63  ```
    64  EquationResult = 46658
    65  FloatValue     = 1.23
    66  IntegerValue   = 1
    67  ListValue      = ["value1", "value2"]
    68  StringValue    = "Foo bar"
    69  
    70  DictValue {
    71    key1 = "value1"
    72    key2 = "value2"
    73  }
    74  ```
    75  
    76  ## Nested conversions
    77  
    78  This test shows how you can convert from and to other formats.
    79  
    80  | Razor | Gotemplate
    81  | ---   | ---
    82  | ```@toPrettyTFVars(data(toTFVars(fromHcl(toHcl(fromJson(toJson(data("!Data"))))))))``` | ```{{ toPrettyTFVars (data (toTFVars (fromHcl (toHcl (fromJson (toJson (data "!Data"))))))) }}```
    83  
    84  ```
    85  EquationResult = 46658
    86  FloatValue     = 1.23
    87  IntegerValue   = 1
    88  ListValue      = ["value1", "value2"]
    89  StringValue    = "Foo bar"
    90  
    91  DictValue {
    92    key1 = "value1"
    93    key2 = "value2"
    94  }
    95  ```
    96  
    97  
    98  ## Merging data structures
    99  
   100  This test shows how you can merge data structures
   101  
   102  ```
   103  {{- $dict_1 := data `{"dict": {"string1": "value1", "string2": "value2"}, "bool1": true, "bool2": false}` }}
   104  {{- $dict_2 := data `{"dict": {"string1": "value2", "string3": "value3"}, "bool1": false, "bool3": true}` }}
   105  
   106  # Gives precedence to the first dictionary
   107  @{dict_3} := merge($dict_1, $dict_2)
   108  @{dict_3.dict.string1} @typeOf($dict_3.dict.string1) == value1 string
   109  @{dict_3.dict.string2} @typeOf($dict_3.dict.string2) == value2 string
   110  @{dict_3.dict.string3} @typeOf($dict_3.dict.string3) == value3 string
   111  @{dict_3.bool1} @typeOf($dict_3.bool1) == true bool
   112  @{dict_3.bool2} @typeOf($dict_3.bool2) == false bool
   113  @{dict_3.bool3} @typeOf($dict_3.bool3) == true bool
   114  ```
   115  {% endraw %}