Transclusion With Argument For Dummie

96 views
Skip to first unread message

kleinfelt...@gmail.com

unread,
Dec 23, 2020, 6:04:15 PM12/23/20
to TiddlyWiki
I'd like to define a tiddler.  Let's call it MessWithYourFolder.  Imagine this tiddler contains something like:

blah-blah
Navigate to C:\{FOLDER_NAME}
blah2-blah2

I'd like to transclude it from one tiddler and tell it to replace {FOLDER_NAME} with "Bob's Folder".  I'd like to transclude it from another tiddler and tell it to replace {FOLDER_NAME} with "Mary's Folder".

I'm thinking it is something like:
  • {{MessWithYourFolder|Bob's Folder}}
  • {{MessWithYourFolder|Mary's Folder}}
When I read about parametric transclusion, it's over my head.  What's the simplest syntax to define a tiddler to be transcluded with a single variable value to be replaced when transcluded, and how do you transclude that tiddler.

TIA

TW Tones

unread,
Dec 23, 2020, 6:56:39 PM12/23/20
to TiddlyWiki
perhaps use a macro definition and make use of the variable substitution?

\define folder-blah()
blah-blah<br>
Navigate to C:\$(folder-name)$<br>
blah2-blah2<br>
\end
<$set name=folder-name value="Bob's Folder">
<<folder-blah>>
</$set>

Regards
Tones

Mark S.

unread,
Dec 23, 2020, 7:06:41 PM12/23/20
to TiddlyWiki
I interpret your desire to make on-the-fly instructions for users.

Contents of MessWithYourFolder:

blah-blah <br/>
Navigate to <$text text={{{ [[C:\]addsuffix{!!title}] }}} /> <br/>
blah2-blah2 <br/>

The <br/> 's are necessary so they don't run together.
The text widget causes the triple brackets to return as text, not a link.
The triple brackets append the title to the directory name. The !!title contains the name of the title of the tiddler passed at invocation.

Invoke like:

{{Bob's Folder||MessWithYourFolder}}

Note that the template goes AFTER the name of the target tiddler, and that they are separated by a double pipe || .

Brian Radspinner

unread,
Dec 23, 2020, 7:11:49 PM12/23/20
to TiddlyWiki
Rather than simple transclusion, you can use a macro with a parameter.

Make a new tiddler and tag it with $:/tags/Macro. Include the following:

\define folderStuff($_$)
blah-blah<br/>
Navigate to C:\$_$<br/>
blah2-blah2
\end

Save this macro tiddler.

In another tiddler where you want the directions to appear, type:

<<folderStuff "Mary's Folder">>
<<folderStuff "Bob's Folder">>
etc...

kleinfelt...@gmail.com

unread,
Dec 23, 2020, 8:06:41 PM12/23/20
to TiddlyWiki
Perfect! Thank you both!  

I see the 'title' variable or $_$, depending on whether I use a transclude or a macro.  What would 2 variables look like? How about 3?

In reality, this is going to be a long, long set of instructions  for setting up 2 routers. 95% or more of the setup is identical, but there are several values which are unique to one router or the other.

Brian Radspinner

unread,
Dec 23, 2020, 9:28:06 PM12/23/20
to TiddlyWiki
With the macro route, you can have multiple parameters...

\define routerSetup(param1:"" param2:"" param3:"" param4:"" param5:"")
Some text to $param1$ goes here. Some more $param2$ can go right here.

On a new line, some $param3$ can also fit. Also, some $param4$ and even $param5$ for good measure.
\end


<<routerSetup "use" "text" "additional stuff" "more text" "MORE TEXT">>

Some more examples can be found here: TiddlyWiki.com -- Macro Definitions in WikiText. You can put default values in between any of the quotes in the first line of the macro definition as needed.

If you are going with many more than that, there's probably a more efficient/easier-to-use way than above that someone else can point you to.
Reply all
Reply to author
Forward
0 new messages