Could you please stop joking around on the SetWidget page regarding examples for the currentTiddler variable?

Okay, so I’m filtering a list, this changes the currentTiddler, right?

<$list filter="[contains:worshipsGod[GODTOBESEARCHED]!sort[at]]">
  <<currentTiddler>><br>
</$list>

Gods are listed in a worshipsGod field that any entity might have.
To make that list thing a generic one, it would need the title of the God, the name, right?

How the frigg to I pass that, man?

This is what I have right now.

<$set name="this" value=  <<currentTiddler>>>

BLARGH should be 'this' of course.

<$list filter="[contains:worshipsGod[BLARGH]!sort[at]]">
  <<currentTiddler>><br>
</$list>

</$set>

How do I get at “this”?

 <<this>> does not work
<this> does not work
$this$ does not work

and all the examples on
https://tiddlywiki.com/static/SetWidget.html

use <<>> macro stuff,
but that doesn’t go in a filter, right?

it should be

like its explained here
https://tiddlywiki.com/static/Variables.html

To me, this should be one of the most made clear things ever.
I DGAF about “Zebra”
I GAF about

pass original currentTiddler as variable to ‘overridden by list’ changed ‘currentTiddler’ so that the overridden one has a reference to the ‘caller’.

perhaps even as a name like “callingTiddler” or something.

Now, I’m not a very smart man so this is partly on me, but I feel like this could be easier.

I have the suspicion that TW has gotten so powerful that simplicity isn’t even considered that much anymore.

Everyone in the core team probably flicks 10 mile long chained filters and widgets and macros out of the sleeve like its nothing.

And yes I still say that with the very high possibility that the solution to this is simple. But I’m not seeing it.
And I’m ‘reading’ the manual.

But maybe I’m just too dumb, lol, not impossible.
Edit: had to put the brackets into a code tag cause …yeah

hnghhhhhhhhhhhhhhhhhhhhhhh

P.S.:
Would be cool to have functions that retrieve variable values instead of symbols like

$Varname$
<Varname>
<<Varname>>
<<<Varname>>>
{{{Varname}}}}
{{Varname}}
{Varname}
oOoGaaBooga\/\/---!$%%^#%$$#--Varname--#$$%#^%%$!---/\/\agooBaaGoOo



and all the other ones
keep the shorthand but whew, give us a longhand for those ‘edge cases’ like filters and macros and whatnot.

varAsText(Varname)
varAsLink(Varname)
varAsNumber(Varname)

or SOMETHING…this context specific stuff is annoying

I don’t quite understand your data structure, but I guess you want:

<$list filter="[contains:worshipsGod<this>!sort[at]]">
  <<currentTiddler>><br>
</$list>

But there’s no reason for “this” (at least in your example) – you can just use the current tiddler value:

<$list filter="[contains:worshipsGod<currentTiddler>!sort[at]]">
  <<currentTiddler>><br>
</$list>

The bracket syntax is needed because everything is being rendered in the context of a markup language (wikitext). So even if everything had functions, it would still need some sort of markup to say “interpret this dynamically”.

Wait, the <this> is without the brackets?
its not [<this>]

yep…it actually works… ghhhh ghhghghghhg

Tripped me up again, where can I read about when to use brackets and not? Cause I think that was the fault in my last topic, too.

Edit:
https://tiddlywiki.com/static/Introduction%20to%20filter%20notation.html
shows an example with [<>] at the bottom… confusing.

And I don’t think I nested these ‘special brackets’ … even though square brackets can be nested it seems.

[contains:worshipsGod[<currentTiddler>]!sort[at]]">
  <<currentTiddler>><br>
</$list>

Right? That’s not nested, right? I didn’t nest the ‘special brackets’.
it’s just
[<currentTiddler>]

Whyyyyyyy

The brackets in filter syntax are not just syntactic delimiters around filter operands… they indicate how each filter operand should be processed.

  • square brackets surround literal values; e.g., operator[sometext]
  • angle brackets surround variable references; e.g., operator<someVariable>
  • curly brackets surround tiddler references; e.g., operator{SomeTitle} or operator{!!somefield}

When used outside filter syntax (i.e., rendered within regular wikitext), these brackets are doubled. This is needed so content that is enclosed in single brackets (e.g., [arglebargle], <gronk>, {frotz}) can be rendered as simple text content, rather than being processed as links, variables, or tiddler field references (e.g., [[TiddlerTitle]], <<someVariable>>, {{!!somefield}})

Hope this helps clear things up for you.

-e

5 Likes

That does clear things up for me somewhat.
Thanks.

The examples just tripped me up. They’re so friendly “try me” and all that but… they have confused me, too.

P.S.: I don’t come from a ‘web’ background at all, so square brackets to me are either array index operators or dictionary lookups, etc.
Probably one of the reasons why I’m struggling.

One more note:

In regular wikitext, content enclosed in single angle brackets (e.g., <gronk>) is seen as HTML/XML syntax which permits use of arbitrary names for elements, like this:

<gronk>
This content is inside a custom "gronk" XML element.
</gronk>

You could then apply styles by using CSS syntax (contained in a tiddler tagged with $:/tags/Stylesheet):

gronk { font-size:large; color:green; }

Note that CSS styling could also be written “inline” (without using a custom XML element and a separate stylesheet), as:

@@font-size:large;color:green;This content is large and green.@@

when rendered, this is processed as:

<span style="font-size:large;color:green;">This content is large and green.</span>

I know there have been some answers already, but I want to give it a try.

TW variables have a scope and can be “stacked”

The code snippets below only make sense, if you try them yourself!

There are several things in TW that change the currentTiddler variable

  • Directly setting currentTiddler with a $set or $let widget.
  • Using a $list widget to enumerate the outputs of a filter.
  • Transcluding another tiddler with the {{curly braces}} syntax.

Set-widget

As I wrote. Variables have a scope. They are valid inside the widget they are defined in.
Procedures and macro definitions are special cases of set-widgets.

Their scope is the whole tiddler.

title: procedures-are-variables

\procedure test() abc
\procedure test() xyz

```
<<test>>  ... Will be xyz 
```

<<test>>  ... Will be xyz 

So the last one wins. The above code is a “shortcut for”

<$set name=test value=abc>
  <$set name=test value=xyz>

  <<test>>

  </$set>
</$set>

Try this:

<$set name=test value=abc>

  <<test>>

  <$set name=test value=xyz>

    <<test>>

  </$set>
</$set>

list-widget

Let’s say I want to create a list of tiddler links, that use the name of the tiddler the code lives in and add “a”, “b” and “c” at the end.

title: myTemplate

\function concat() [<currentTiddler>] [<title>] +[join[-]]

<$list filter="a b c" variable="title">
  <$link to=<<concat>> /><br>
</$list>

By default the list-widget would “overwrite” the currentTiddler variable, that’s why we can provide a new variable name. In this case title

  • The list-widget iterates over a, b, c and sets the title variable.
  • The currentTiddler stays the same.

The currentTiddler variable is the tiddler-title, the code lives in.

The concat function can be implemented in several more ways, depending on the usecase.


Transclusion

If you create a new tiddler named: test … You can play with templates.

  • The first transclusion will set the currentTiddler variable to myTemplate
  • The second transclusion will pass the currentTiddler variable on to the template
  • The third example passe the name “xxx” to the template, which will be used as currenTiddler
title: test

{{myTemplate}}

---

{{||myTemplate}}

---

{{xxx||myTemplate}}

Docs about transclusion: https://tiddlywiki.com/#Transclusion%20in%20WikiText


About your code

First things first. Syntax.

There is a syntax error here. It’s not possible to have spaces between = and <<currentTiddler>>


  • In the example below the tiddler title is BLARGH
    • When a tiddler is rendered in the story, the UI defines the currentTiddler variable and sets it to the tiddler-title, so it can be used in the tiddler body text.
  • Then the set-widget form your code will set the this variable to <<currentTiddler>> which is BLARGH as defined above.
    • IMO you got that right, but IMO there was a syntax problem
  • Then the contains-operator will list all tiddlers that have a field named: worshipsGod
    • Internally the filter is automatically expanded to [all[tiddlers]contains:worshipsGod . . .
    • Then it will compare the value of worshipsGod field with the value of the variable <this>

title: BLARGH 

<$set name="this" value=<<currentTiddler>>>

BLARGH should be 'this' of course.

<$list filter="[contains:worshipsGod<this>!sort[at]]">
  <<currentTiddler>><br>
</$list>

</$set>

According to the documentation, the list-widget will use the variable <<currentTiddler>> inside its body.
But
That can be changed with the “variable” parameter. So you can choose any name, that fits helps you to make the code more understandable.

<$list filter="[contains:worshipsGod<this>!sort[at]]" variable="name-of-god">
  <<name-of-god>><br>
</$list>

You can use the attached JSON tiddlers and play with the examples above.
Playing around with the stuff should make things clearer

Hope that helps

Have fun!
mario

variable-scopes.json (1.1 KB)

7 Likes