Using Dynamic Variables
Dynamic variables allow you to define calculations or operations once and reference them in multiple expressions.
This is implemented with the
<vdl-var> element which defines a variable's name and its value. Once defined, the variable can be referenced throughout the rest of a View. Variable names should be unique and will be either
globally-scoped or
scenario-scoped, depending on where you define them.
![]() |
Note A
vdl-var component will feature an orange border when placed on the
artboard in
View Designer. This designates that the item will not be visible in the view when it is published, although the value stored in the var can be displayed if it is attached to a
vdl-text component.
|
Globally scoped dynamic variables
The following view illustrates how to create and use globally-scoped variables.
View Designer
Code editor
<vdl version="4.7"> <vdl-page> <vdl-var name="title" value="Portfolio Optimization risky share types"></vdl-var> <vdl-var name="rows" value="=scenario.entities.ShareIds"></vdl-var> <vdl-section heading="=vars.title"> <vdl-row> <vdl-column vdl-repeat="=row in vars.rows" heading="=row.value" size="2"> <div vdl-text="=scenario.entities.Shares_HighRisk(row.value) && scenario.entities.Shares_fraction(row.value).value ? 'Yes' : 'No'"></div> </vdl-column> </vdl-row> </vdl-section> </vdl-page> </vdl>
The vdl-text attribute has been assigned a ternary guard expression to ensure the value is set. The <vdl-var> elements are positioned outside the <vdl-page> element to enable global scope.
This renders as:
A dynamic variable that is scoped across just the scenario must contain an attribute that identifies its parent scenario by index. The following, changed code snippet illustrates the principle:

Rendered Global Dynamic Variables
View Designer

<vdl version="4.7">
<vdl-page>
<vdl-section>
<vdl-row>
<vdl-column vdl-repeat="=s,i in scenarios">
<vdl-var name="title" value="='Portfolio Optimization scenario: ' + s.props.name" scenario="=i"></vdl-var>
<span vdl-text="=s.vars.title"></span>
</vdl-column>
</vdl-row>
</vdl-section>
</vdl-page>
</vdl>
The scenario index in the preceding example is captured in the
<vdl-repeat> element as the loop variable
i, which is then used as the scenario index for the
<vdl-var> element. For more on
vdl-repeat, see
Using Loops with Arrays and Sets.