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 VDL view. Variable names should be unique and can be either globally-scoped or scenario-scoped, depending on where you define them.
The following view illustrates how to create and use globally-scoped variables.
<vdl version="4.1">
<vdl-var name="title"
value="Portfolio Optimization risky share types"></vdl-var>
<vdl-var name="rows"
value="=[0,1,2,3,4]"></vdl-var>
<vdl-page>
<vdl-section heading="=vars.title">
<vdl-column vdl-repeat="=row in vars.rows"
heading="=row"
size="4">
<p vdl-text="=scenario.entities.RISK.length &&
scenario.entities.RISK[row].value ?
scenario.entities.RISK[row].value :
'' "></p>
</vdl-column>
</vdl-section>
</vdl-page>
</vdl>
Note the ternary guard expression assigned to the vdl-text attribute. Also note the position of the <vdl-var> elements - outside a <vdl-page> element - this is what gives them global scope.
This renders as:

Rendered Global Dynamic Variables
To use a dynamic variable - say,
title - at the scenario scope, it needs to contain an attribute that identifies its parent scenario by index. The following, changed code snippet illustrates the principle:
<vdl version="4.1
<vdl-section>
<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-section>
</vdl-page>
</vdl>
Above, the scenario index 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. See
Using Loops with Arrays and Sets for further details of
vdl-repeat.