github.com/upcmd/up@v0.8.1-0.20230108151705-ad8b797bf04f/tests/functests/c0082.yml (about)

     1  doc_meta: |
     2    folder: dvars
     3    title: datakey as source
     4    head: |
     5      Previously when we render a dvar, we implicitly use all vars from global runtime scope, however sometimes we need to use a specific data object as the data source to render dvar.
     6  
     7      In this case, we showcase to render dvar value using data field as source rather the global var name space
     8  
     9    sections:
    10  
    11      - title: What's the difference
    12        content: |
    13          Please note the datakey tag is used and it is pointing to a variable named student. In this caes the reference of {{.school}} will locate the school from global runtime var: .student.school
    14  
    15          Without this tag, the reference of {{.school}} will try to locate a var name school from global runtime
    16  
    17          Please also note that the datakey could be a dynamic using var, this gives you a little extra programmingbility for dynamic routing when you combine with logical if tag
    18  
    19      - title: Demo
    20        log: yes
    21  
    22  
    23  notes:
    24    goal:
    25      - showcase the dvar to render value using data field as source rather the global var name space
    26  
    27  vars:
    28    student:
    29      name: Tom
    30      gender: Male
    31      school: Sydney Grammar
    32    nsw:
    33      sydney:
    34        sgschool:
    35          student:
    36            name: Tom
    37            gender: Male
    38            school: Sydney Grammar
    39    aaa: aaa
    40    datapointer: student
    41  
    42  tasks:
    43    -
    44      name: task
    45      task:
    46        -
    47          func: cmd
    48          dvars:
    49            - name: student_info
    50              value: 'my name is:{{.name}} and I am in {{.school}}'
    51              datakey: student
    52              flags: [vvv]
    53          do:
    54            - name: print
    55              cmd: '{{.student_info}}'
    56        -
    57          func: cmd
    58          dvars:
    59            - name: student_info
    60              value: 'my name is:{{.name}} and I am in {{.school}}'
    61              datakey: '{{.datapointer}}'
    62              flags: [vvv]
    63          do:
    64            - name: print
    65              cmd: '{{.student_info}}'