github.com/upcmd/up@v0.8.1-0.20230108151705-ad8b797bf04f/tests/functests/c0075.yml (about) 1 doc_meta: | 2 folder: template 3 title: range and outer value 4 head: | 5 Demo how to loop through using golang template and a few different ways to reference the iterating item. Also it shows how to access the outter value within the loop 6 7 When execution begins, $ is set to the data argument passed to Execute, that is, to the starting value of dot. 8 9 ``` 10 {{with .Inner}} 11 Outer: {{$.OuterValue}} 12 Inner: {{.InnerValue}} 13 {{end}} 14 ``` 15 16 sections: 17 - title: Demo 18 log: yes 19 20 docs: | 21 22 vars: 23 person: peter 24 managers: 25 - tom 26 - jason 27 - alice 28 29 dvars: 30 31 #extra: {{if pipeline}} T1 {{else if pipeline}} T0 {{end}} 32 - name: var_with_range 33 value: "{{range .managers}} x {{end}}" 34 flags: [vvv,] 35 36 - name: var_with_range_item 37 value: "{{range $x:=.managers}} {{$x}} {{end}}" 38 flags: [vvv,] 39 40 - name: var_with_range_item_simpler 41 value: "{{range .managers}} {{.}} {{end}}" 42 flags: [vvv,] 43 44 - name: var_to_ref_to_outside_of_range_from_within_range 45 desc: | 46 the direct reference to try to access out of scope in range will not work 47 expect a warning from this execution 48 value: "{{range $x:=.managers}} {{.person}} {{end}}" 49 flags: [vvv,] 50 51 - name: var_directly_ref_to 52 value: "{{.person}}" 53 flags: [vvv,] 54 55 - name: var_to_ref_to_outside_of_range_from_within_range_fixed 56 desc: | 57 use $. to access out of scope variable 58 value: "{{range $x:=.managers}} {{$.person}} {{end}}" 59 flags: [vvv,] 60 61 62 tasks: 63 - 64 name: task 65 task: