2018-09-28 15:01:32 +00:00
caption: importvariables
2014-06-12 17:01:33 +00:00
created: 20140612142500000
2022-10-09 16:43:38 +00:00
modified: 20180928150043777
2014-09-10 23:06:19 +00:00
tags: Widgets
2014-06-12 17:01:33 +00:00
title: ImportVariablesWidget
type: text/vnd.tiddlywiki
! Introduction
The ImportVariablesWidget imports macro and variable definitions from a list of other tiddlers and makes them available to its children. For example:
```
<$importvariables filter="[tag[mySpecialMacros]]">
All the macros defined in tiddlers with the tag "mySpecialMacros" are available here
</$importvariables>
```
! Attributes and Content
The content of the importvariables widget is the scope within which the imported variable definitions are available.
|!Attribute |!Description |
2014-09-10 22:42:13 +00:00
|filter |[[Tiddler filter|Filters]] defining the tiddlers from which macro definitions will be imported |
2014-06-12 17:01:33 +00:00
! Global Macros
So-called global macros are implemented within the main page template ([[$:/core/ui/PageTemplate]]) by wrapping the page content in the following importvariables widget:
```
<$importvariables filter="[[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]]">
...
</$importvariables>
```
2018-09-28 15:01:32 +00:00
! `\import` Pragma
2022-09-21 09:41:03 +00:00
<<.from-version "5.1.18">> The [[Pragma: \import]] is an alternative syntax for using the ImportVariablesWidget. For example, the previous example could be expressed as:
2018-09-28 15:01:32 +00:00
```
2020-12-03 22:27:21 +00:00
\import [[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]]
2018-09-28 15:01:32 +00:00
```