Working with Conditional VDL Attributes
Any valid VDL expression can be used with a conditional VDL attribute as long as it evaluates to a value that can be interpreted as true or false.
The vdl-if Conditional
<div vdl-if="=scenario.entities.boolScalar.value"> <h1>Optimal return</h1> </div>Above, the <div> and <h1> elements will only be shown if the value of the boolScalar scalar is true.
<vdl-section vdl-if="=scenarios.length > 1"> ... </vdl-section>vdl-if expressions are evaluated once all page data is loaded, and the conditional content is not included until the evaluation.
<div vdl-if="=true"> I am visible when the data for this view is loaded. </div>
The vdl-visible Conditional
This is similar to vdl-if except that the element it is placed upon - and its children - are never removed from the view. When supplied with an expression which evaluates to false, vdl-visible applies a style that causes the element to not be displayed.
The difference from vdl-if is that the affected elements are still in the view DOM and can be manipulated even while not visible. This is important when there are sections of the view that need to be kept up-to-date even when they are perhaps not visible.
The vdl-css Conditional
This attribute is similar to vdl-if and vdl-visible. It adds CSS classes to the element on which it is attached if the expression evaluates to truthy. It is different from vdl-if and vdl-visible in that it takes an object as a value.
<div vdl-css="={danger: scenario.entities.boolValue.value, error: scenarios.length===0"> ... </div>In each case, the key entry in the object is the name of the class to add, and each value is an expression that evaluates to true or false.