ELI5 on how \import and $importvariable function?

I’ve been reading up on \import at Tiddlywiki, but I don’t understand how it functions to be completely honest.

When looking at the tiddler in question, the example doesn’t make much sense and even when placing it into a fresh TW and creating a tiddler tagged how the example states, nothing happens.

I could very well be misunderstanding how it works, but should I not be able to use \import to import <$vars>?

What I want to achieve is having a Tiddler, lets call it “Soccer Team”, and inside is “<$vars timmy=”[[timmy|goalie timmy]]" jack="[[jack|player jackson]]"></$vars>" and it is tagged “MyTeam”

and in another tiddler, titled “Attendance” to just type “\import [tag[MyTeam]]

<<timmy>> and <<jack>> are out sick.”

I think I’ve figured out what I’ve done wrong.

Vars is a widget, whereas this only imports macros, I found this out just on a whim :sweat_smile:

My question does still stand as far as ‘how to import $vars from one tiddler to another?’ for anyone who might have an answer

Please provide links to the code examples you are talking about.

No. At the moment it’s macro definitions only by intention. While macros are very similar to variables, they are not exactly the same thing.

Sure!

ImportVariablesWidget is what I was reading, and the mistake I made was assuming Variable Definitions was what $vars was creating, but that was not the case.

As I wrote. That’s not possible. <$vars is deprecated and <$let should be used instead.

<$let and <$vars have a “scope”. They are only active between the start tag <$let> and the end-tag </$let> … If the end-tag is missing, the end of the tiddler is the end of the scope.

Macros have a special “marker” in the parse-tree, that makes it possible to import them.

\define global-macro() Some text

and open it with the parse-tree visible. There is a special marker isMacroDefinition

Well, that’s a shame, thanks for the information!

You can achieve, what you want with the following example. Where the definitions are in 1 tiddler and the macro calls are in the other tiddler. If you don’t want to use $:/tags/Macros you can use the \import pragma in the second tiddler

I did it in 1 code element for testing.

\define timmy() [[timmy|goalie timmy]]
\define jack() [[jack|player jackson]]


<<timmy>> and <<jack>> are out sick. 

The importvariables widget imports set widgets. This also works for macros because macros are implemented as set widgets.

Note that only set widgets are only imported if they are the first widget in a tiddler and only the first set widget will be imported, as well its first child if it is a set widget and so on.

If you place only the following in a tiddler, you can import these variables into another tiddler:

<$set name="timmy" value="[[timmy|goalie timmy]]">
<$set name="jack" value="[[jack|player jackson]]">
<$/set>
<$/set>

That’s actually what I did to figure out how \import, funnily enough.

I guess what happened was I misread the title of the tiddler to mean “import the Variables Widget”, and not “importvariables is a widget.” which was my bad :sweat_smile:

I think that’s way to “brittle” to be used in maintainable code. I personally would highly suggest to avoid constructions like that.

I think we need to fix the wording in the docs tiddler. IMO it’s misleading.

It definitely needs to be used with care and is somewhat unintuitive. However it is the only means we currently have to dynamically define a variable in a tiddler using filters and then import it into another tiddler.