title: SetWidget created: 201311151827 modified: 20141113212520422 tags: Widgets caption: set ! Introduction The set variable widget assigns a value to a specified [[variable|WidgetVariables]]. The new value of the variable is availale to the content within the set variable widget. ! Content and Attributes The content of the `<$set>` widget is the scope for the value assigned to the variable. |!Attribute |!Description | |name |The name of the variable to assign (defaults to "currentTiddler") | |value |The value to assign to the variable if the filter is missing or not empty | |filter |An optional filter to be evaluated and assigned to the variable (see below) | |emptyValue |The value to assign to the variable if the filter is present and evaluates to an empty list (see below) | !! Simple Variable Assignment The simplest way of using set variable widget assigns a string to a variable. The following example assigns a literal string ``` <$set name="myVariable" value="Some text"> <$text text=<>/> ``` Both the name and value attributes can be transcluded. For example: ``` <$set name=<> value={{template!!text}}> <$text text=<>/> ``` !! Conditional Variable Assignment This form of the set variable widget chooses one of two specified values according to whether a filter evaluates to an empty list. Here's an example that sets a variable according to whether the current tiddler is called "myMagicTitle": ``` <$set name="myVariable" filter="[all[current]field:title[myMagicTitle]]" value="It's magic" emptyValue="It's not magic"> <$text text=<>/> ``` !! Filtered List Variable Assignment This form of the set variable widget evaluates the filter and assigns the result to the variable as a space-separated list (using double square brackets for titles containing spaces). ``` <$set name="myVariable" filter="[tag[Introduction]]"> <$text text=<>/> ```