1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-04 11:13:15 +00:00
TiddlyWiki5/editions/prerelease/tiddlers/VarsWidget.tid
Felix Hayashi 740627795f This widget allows the user to set multiple variables in one go.
It thereby reduces code complexity that would arise when setting
many variables using "<$set>".

```
\define helloworld() Hello world!
<$vars greeting="Hi" me={{!!title}} sentence=<<helloworld>>>
  <<greeting>>! I am <<me>> and I say: <<sentence>>
</$vars>
```

How this Widget differs from the set widget:

 * Variables may be created by using the "key=value" notation
   that you already know from widgets like action-setfield.
 * You cannot specify a fallback ("emptyValue")
 * You cannot use a filter to produce a conditional variable assignement

Original discussion that led to the creation of this widget:
https://github.com/Jermolene/TiddlyWiki5/issues/1610
2015-04-27 17:07:13 +02:00

53 lines
1.4 KiB
Plaintext

title: VarsWidget
created: 20150426115958020
modified: 20150426115958020
tags: Widgets
caption: vars
! Introduction
The ''vars'' widget allows you to set multiple variables in one go. It thereby reduces code complexity that would arise when setting
many variables using the [[SetWidget]].
! Content and Attributes
The content of the `<$vars>` widget is the scope for the value assigned to the variable.
|!Attribute |!Description |
|//{attributes not starting with $}// |Each attribute name specifies a variable name. The attribute value is used as variable assignement |
! Examples
Consider a case where you need to set multiple variables.
Using the `<$vars>` widget, this situation may be handled in the following way:
```
\define helloworld() Hello world!
<$vars greeting="Hi" me={{!!title}} sentence=<<helloworld>>>
<<greeting>>! I am <<me>> and I say: <<sentence>>
</$vars>
```
In contrast, here is the same example, but using the `<$set>` widget instead:
```
<$set name="greeting" value="Hi" />
<$set name="me" value={{!!title}} />
<$set name="sentence" value=<<helloworld>> />
<<greeting>>! I am <<me>> and I say: <<sentence>>
</$set>
</$set>
</$set>
```
! Remarks
It should be noted that this widget differs from the set widget in the following ways:
* You cannot specify a fallback (also known as "emptyValue")
* You cannot use a filter to produce a conditional variable assignement