github.com/coveo/gotemplate@v2.7.7+incompatible/docs/doc_test/comments.rendered (about) 1 {% include navigation.html %} 2 {% raw %} 3 # Comments in gotemplate 4 5 It is important to notice that gotemplate doesn't know the language you are using and any identified gotemplate code is executed no matter where it is. Comments in the 6 host language mean nothing to gotemplate and will be evaluated. 7 8 ## Pseudo comment 9 10 If you insert gotemplate code into file that contains another kind of code such as hcl, json, yaml, xml, java, c# or any other language, your code editor or linter may complains 11 because it will detect invalid characters. 12 13 To solve that problem, it is possible to inject pseudo comment into you code to hide the gotemplate code to your editor. The gotemplate is still interpretated, but obfuscated to the editor. 14 15 **It is important to render code that is valid for the host language.** 16 17 * `#!` is a pseudo comment that will removes the `#!` part but render everything after. 18 * `//!` is also used as pseudo comment and behave exactly as `#!`. 19 * ` ` is used to specify pseudo comment in a multi line context, everything inside is rendered, but `` and `` are removed. 20 21 | Razor expression | Go Template | Render | Note 22 | ---------------- | ----------- | ------ | ---- 23 | `# 4` | `# 4` | `# 4` | gotemplate code after # comment 24 | `// 4` | `// 4` | `// 4` | gotemplate code after // comment 25 | `/* 4 */` | `/* 4 */` | `/* 4 */` | gotemplate code within /* */ comment 26 | `4` | `4` | `4` | Pseudo comment #! 27 | `4` | `4` | `4` | Pseudo comment //! 28 | ` 4 ` | `4` | `4` | Pseudo block comment with 29 30 ## Real gotemplate comment 31 32 If you really want to add comment to your file and wish them to not be rendered, you must use the following syntax. 33 34 * ` 35 * ` 36 * `` enclosing every character after the comment up to the end of line. */}} 37 * ` 38 * `` is used to generates gotemplate comment in a multi-lines context. 39 40 | Razor expression | Go Template | Render | Note 41 | ---------------- | ----------- | ------ | ---- 42 | `4 43 | `4 44 | `4 ` | `4` | <no value> generates a real gotemplate comment */}} 45 | `4 ` | `4` | @// also generates a real gotemplate comment */}} 46 | `4 ` | `4 ` | `4` | is used to generate multi-lines gotemplate comment 47 48 Like most of the gotemplate razor syntax, you can add the minus sign to your `@` command to render space eating gotemplate code. 49 50 | Razor expression | Go Template | Note 51 | ---------------- | ----------- | ---- 52 | `` | No space eater */}} 53 | `` | Left space eater */}} 54 | `` | Right space eaters */ -}} 55 | `` | Left and right space eaters */ -}} 56 57 ## Examples 58 59 ### Example with JSON code 60 61 ```go 62 { 63 "Str": "string", 64 "Int": 123, 65 "Float": 1.23, 66 "PiAsString": "3.141592653589793", 67 "ComputedAsString": "122", 68 69 /* You can use the special << syntax to extract the value from the string delimiter */ 70 "Pi": 3.141592653589793, 71 "Computed": 122, 72 } 73 ``` 74 75 will give : 76 77 ```go 78 { 79 "Str": "string", 80 "Int": 123, 81 "Float": 1.23, 82 "PiAsString": "3.141592653589793", 83 "ComputedAsString": "122", 84 85 /* You can use the special << syntax to extract the value from the string delimiter */ 86 "Pi": 3.141592653589793, 87 "Computed": 122, 88 } 89 ``` 90 91 ### Example with HCL code 92 93 ```go 94 Str = "string" 95 Int = 123 96 Float = 1.23 97 PiAsString = "3.141592653589793" 98 ComputedAsString = "122" 99 100 // You can use the special << syntax to extract the value from the string delimiter 101 Pi = 3.141592653589793 102 Computed = 122 103 ``` 104 105 will give: 106 107 ```go 108 Str = "string" 109 Int = 123 110 Float = 1.23 111 PiAsString = "3.141592653589793" 112 ComputedAsString = "122" 113 114 // You can use the special << syntax to extract the value from the string delimiter 115 Pi = 3.141592653589793 116 Computed = 122 117 ``` 118 119 {% endraw %}