Variables usage

Hello!

I’m a little confused when trying to use variables.

Mainly, I have a lot tag tiddlers, and I like when they contain toc-selective-expandable, so I can effectively navigate through and grasp the contents of my wiki. But when creating new tag each time I need to copy/paste and then modify the name in toc, so it shows proper list. Therefore I’m interested in creating a template:


<$macrocall $name="toc-selective-expandable" tag="CurentTiddlerNameHere" sort="sort[created]" />

but nothing I try works :confused: The following things properly return the current tiddler name, when used by themselves, but not when put in macrocall:


<<currentTiddler>>
<$text text=<<currentTiddler>>/>
<$text text={{{ [<currentTiddler>] }}} />

So first of all, how can I use such variable in macrocall?

And the other thing, what is the difference between those 3 currentTiddler notations? I have also seen something like !!title, or something like this, so I would be most grateful if someone could explain to me what’s going on.

Oh and btw. I also happen to struggle with usage of mathematical operators. I’m interested in defining 2 variables, let’s say x=2 and y=3, and be able to perform x+y to obtain the result. Again, I would be most thankful for pointing out how to do it.

Have a great day!

Did you try tag=<<currentTiddler>>?. Also its wise to put this in a tiddler tagged $:/tags/ViewTemplate so it appears on all tiddlers, and wrap it with a list widget to make it conditional ie on if has tags etc…

Unless you install a plugin for mathematics we use operators in filters to do maths. It’s quite simple once you are familiar with filters.

So you can do a lot in a single filter but using the let widget to define the variables and calculations involved is a self documenting and easy to read approach.

<$let x=2 y=3 sum={{{ [<x>add<y>] }}}>
<<sum>>
</$let>
  • <<currentTiddler>> display the value in the variable currentTiddler

  • <$text text=<<currentTiddler>>/> display the value in the variable currentTiddler but convert to plan text. Nop camel case seen, not a link etc

  • <$text text={{{ [<currentTiddler>] }}} /> just another way to do the last example using the triple curly braces “filtered transclusion” to evaluate a filter

2 Likes

Hello!

tag=<<currentTiddler>> indeed worked! Though the result was not (and is not) visible in the preview pane, which is a slight incovenience. I also added the $:/tags/ViewTemplate tag, which resulted in exactly the outcome I desired (thank you so much!!!) As you also suggested, I’ll try to wrap it with a list widget, but it’d be also most welcomed if you could show an example of such conditionality.

Also, before I added ViewTemplate tag, I tried to use it via Tiddler transclusion, but it didn’t work at all.

So in tiddler named ''Template_1" there is

<$macrocall $name="toc-selective-expandable" tag=<<currentTiddler>> sort="sort[created]" />

and what I put in content of other tiddler is {{Template_1}} and nothing was displayed. Do you know the reason for that?

And regarding mathematics, I’ll experiment with those solutions later this week. Thank you once again!

To transclude a tiddler and use it as a “template” for another tiddler, use this syntax

{{||Template_1}}

Note the “||” double vertical bars. This indicates that the “Template_1” tiddler’s content will be displayed, while using the containing tiddler’s field values (including the <<currentTiddler>> variable, which is the same as the {{!!title}} field value). Without the “||” vertical bars, the transclusion uses the “Template_1” tiddler’s field values, and thus the “toc-selective-expandable” macro’s tag=... parameter will always be tag="Template_1".

enjoy,
-e

1 Like

Thank you! It really did the trick. Right now I’m figuring out how to do some maths, using Evan Balster’s TiddlyWikiFormula :slight_smile:
And I will also try to figure out how make templates conditional, since that’s not so clear for me yet.

To do this, in a tiddler tagged $:/tags/ViewTemplate

<$list filter=" condition " variable=nul>

conditional content

</$list>

The condition filter for the current tiddler may be;

  • has a particular field name with a value `[all[current]has[fieldname]]"
  • tagged tagname [all[current]tag[tagname]]
  • or a global setting [{$:/config/design-mode}match[yes]]

Note;

  • by setting variable=nul the current tiddler variable remains the tiddler displayed
  • I hope that is clear.
1 Like

Mind blowing! :heart_eyes: Thanks to your help I could create all the desired features in my wiki. You guys are the best! :grinning_face_with_smiling_eyes:

No problem, this is a fundamental pattern to use in Tiddlywiki but now another approach available is the cascades but you can look into that another day :nerd_face:

1 Like