How to refer to tiddlers and/or fields in filters/transclusions through the various brackets, etc

After returning to Tiddlywiki just recently, I have become more aware of problems I am having when programming tiddlywiki behaviour.

The main issue is : how to refer to tiddlers and/or fields in filters/transclusions through the various brackets, etc…

This is a major issue as understanding this will allow me to make things work.

I appreciate the majority of readers of this list are (very) experienced and probably do not see what the problem is. And before you ask, I have been coding for over 30 years in various languages, so I know how to code.

Don’t just answer with - read the manual! I constantly read the manual but find little actual helpful advice. PMario asked me, in my last question about tiddler titles, what searches have I done to attempt to answer my problem. I can’t tell him as my searches are so many and varied, as in this case.

For example, my current problem is: produce a viewtemplate for tiddlers having a tag People, so that when I access a person’s tiddler, it lists all other tiddlers have the tag ‘the title of the current tiddler’.

For example, I have a tiddler ABC that has a tag Jansen, Bob. Now when I view the Jansen, Bob tiddler that has the tag People, I want to see ABC listed along with all other tiddlers have the tag, Jansen, Bob. Simple request, surely.

I know I can do it by explicitly coding <$list filter="[tag[Jansen, Bob]]" /> in the text field of the Jansen, Bob tiddler. But what I would like is a general solution coded into a viewtemplate tiddler which replaces Jansen, Bob (in the example above) with the title of the current tiddler. In other languages, I would do this by passing a parameter to a function, the parameter being the title of the current tiddler and returning the titles of matching tiddlers for display.

I have spent many frustrating hours so far trying different solutions from examples in the documentation but the solution still escapes me. I am sure it is simple, but can not find any example in the documentation.

If I see a possible example and want to see the actual code, I cant’ because all examples are encoded as, for example, <<.operator-example 1 “[all[shadows]]”>>. Hardly helpful!

I was excited by the possibility of <$list filter="[tag[all[current]]]" /> as the documentation implies that all[current] refers to the title of the current tiddler. Problem solved… but this does not work, yet reading the manual implies to me that it would.

Which returns me to my main issue, the documentation is missing explicit details to how to address tiddlers/fields in filters/transclusions/ filtered transclusions/??
It might include advice on when to use variables or macros/parameters, etc. But all in real world situations.

I would suggest the expanding the tiddlywiki documentation to include real world examples and allow the user to see the actual code in use in context.

If anyone has the solution to my immediate problem, I’d be (nearly) eternally grateful.

bobj

would this do what you are looking for?

<<list-links filter:"[tag<currentTiddler>] +[sort[title]]">>

I have a TW that keeps track of books being processed for a project. This comes from a tiddler titled “Processed - Done”, and lists all the book entries that have a tag of “Processed - Done” (as opposed to “Processed - Needed”, “Processed - Decide”, etc.)

There are other tiddlers for the “Needed” and “Decide”, etc. possiblities, and i use that same single line in each.

(oops - forgot to mark that line “preformatted”)

You mean this?

Read everything in there (screenshot below). And don’t allow yourself to get stuck on any point. If something doesn’t make sense, let it not make sense.

Keep pushing through all of it so that you have a full “inventory of things”. When you reach the end, do it again. Every time, things that did not make sense previously will suddenly make sense as you start tying all the bits together.

Your thirty some years of programming might be getting in your way. If you want to have an easy time coding in TW, it helps to have the same mindset as SQL programming (not PL/SQL; I mean SELECT statements; as in the relational algebra: the math behind SQL).

@Bob_Jansen as dicussed place the following in a tiddler tagged $:/tags/ViewTemplate which makes it display on every tiddler;

  • But the condition means it willonly show on tag tiddlers
<$list filter="[all[current]is[tag]]" variable=~>
   <$list filter="[tag<currentTiddler>]" counter=item>
      <$list filter="[<item>match[1]]"><h3>''Tagging tiddlers''</h3></$list>
      <$link/><br>
   </$list>
</$list>

The outer list Line 1 & 6 is the conditional list

  • It tests if the currentTiddler is a tag and only displays line 2-5 if it is
  • The variable equal uses ~ thus leves the value of currentTiddler as it is.

The second list line 2 & 5 lists all tiddlers when the tag is the currentTiddler

  • I also added counter=item so inside I will only display the title is there is one or mopre results Line 3

The 4th line <$link/><br> by default links to the currentTiddler which will be set here to each tiddler which is tagged [tag<currentTiddler>],

You could modify the condition to further resrict on which tiddler you want this to apear.

  • eg [all[current]tag[contact]]
  • or [all[current]object-type[contact]] ie fieldname[value]

You could also determin when in the items tagged $:/tags/ViewTemplate you want it to display with the list-before or list-after fields.

  • eg list-after=$:/core/ui/ViewTemplate/body

Note:
This design uses an unwitten rule, make your code operate on the current tiddler, this allows it to be used in any tiddler, or any list which also changes the current tiddler. Thus you can turn it into a macro. Notice how the inner list(s) use current tiddler by not using variable=name in the list widget.

Terry,

I implemented your suggestion and it initially worked. I quit the browser having saved the change viewtemplate tiddler. Went back into tw again and duplicated the ‘working’ template but for tag ‘exhibitions’. It did not work, it displayed four entries each the same as the other. Tried displaying person’s tiddler and it also now displayed four identical entries.

No idea why this behaviour is happening after I quit TW and then went back into it again. Certainly this is not behaviour I would expect with any other programming language .

TW is weird indeed!

Bobj

I will upload the tw file and associated data to my server tomorrow so people can have a look at the code.

Bobj

An update that makes things clearer.

I removed all user defined viewtemplate tiddlers except for one, called $:/TLS/ViewTemplate/People. This tiddler has Terry’s solution in the text field.

Now all tiddlers with one of these tags, tags People, Places, Organisations and Exhibitions, show their correct list of tiddlers with tags of the title of the current tiddler. So this one viewtemplate seems to apply to all user tiddlers whereas I expected it, in my case, to apply to People tagged tiddlers only. This also implies, to me, that if you use a viewtemplate tiddler, you must include a filter to apply the template to one tiddler type, and other filters for other tiddler types. So you end up with a humongous template tiddler or multiple viewtemplate tiddlers each having a filter for just the tiddler type they should apply to.

So it seems, that the situation of four identical entries occurred because there were four user defined viewtemplate tiddlers.

In discussion with @TW_Tones, I now find out that my knowledge and experience of TW is with TWClassic and things have changed a great deal with current TW.

It also indicated that @TW_Tones solution needs to be considered in more detail.

So I need to unlearn a lot and. Relearn even more. Sigh……

Maybe the documentation should mention this explicitly.

Bobj

Oh, this! Yes, I made this transition a couple years ago, and it took me quite a while to unlearn all the “for each” habits I had developed (and in my case, the one function that was easier in Classic, which is handled in the freelinks plugin for TW5). I feel your difficulty!

One new(ish) development in TW5 — whose power may be of interest to you — is cascades. Rather than having lots of view templates stacked up within each tiddler (with each template including a list-filter-check for all the conditions under which it should display nothing), a cascade (same meaning as in css’s cascading style sheets) allows a series of conditions, where the first one satisfied settles which result applies.

I won’t spam you with questions and suggestions about how and whether this may be what you need, but wanted to put it on your radar. :slight_smile:

Thanks @Springer, I had come across a mention of this but have not had the opportunity to check it out. I will mow.

Bobj

I would like to close this issue now. The main problem is my lack of understanding TW5 differences from TWClassic. Also the documentation suggestions are not actionable here, but hopefully they are taken on board by whomever manages the documentation.

I would suggest, howeveer, that a simple demo project might make sense for novices to get their head around TW5. Let them build it from an empty TW5. It will not obviously contain every option but a few real world facilities, like filter examples, would be of great benefit. I find the examples in the documentation, unless explicit, lack context and thus are hard to translate into my issue space.

bobj

It is important to note, it seems to me the list of tagged items solution I gave is working for me, in fact I just placed it in a wiki of my own. Or has your requirement changed. Let us know or open a new thread when you need to.