-
Notifications
You must be signed in to change notification settings - Fork 0
Parent variables
haskelt edited this page Feb 1, 2022
·
2 revisions
Sometimes it is useful to be able to access variables defined for the node one level up in the XML tree, i.e., the parent of the current node. Consider the following source file:
<page>
<radio-group name="my_radio"/>
<radio-option value="option1" label="Option 1"/>
<radio-option value="option2" label="Option 2"/>
</radio-group>
</page>
Because of how radio groups work in HTML, if we want the user to only be able to select one option, each option has to have the same name value. We can implement this in the template for radio-option like this:
<input type="radio" name="{{parent.name}}" value="{{this.value}}"/>
<label for="{{this.value}}">{{this.label}}</label>
This tells Salal to get the value of value and label from the attributes of the current node, but to get the value of name from the attributes of the parent node (i.e., radio-group).
- Home
- About Salal
- Installation
- Tutorials
- Core concepts
- Getting more out of Salal
- Advanced topics
- Change log