$reveal if <<currentTiddler>> is mentioned in field of a different tiddler?

Hi! I’m new here, so hopefully this question makes sense. I know most of the basics of TiddlyWiki, but I’m by no means an expert.

Context:
OS: Windows 11
Browser: TiddlyDesktop
TW Version: 5.3.1
In the context of my wiki, Fount is a source/published work

I’m working on a TW for a class I’m taking, and in it I’ve got tiddler types for People and Founts. The way I currently have it set up is that Fount tiddlers have a field for author(s). People tiddlers do not have a field for Founts they have authored.

I’m currently trying to set up a view template for my Person tiddlers. I’m following the workflow outlined in Grok TiddlyWiki (Grok TiddlyWiki — Build a deep, lasting understanding of TiddlyWiki).

I want to be able to display the works authored by the Person, but only reveal that information if the Person has actually authored a Fount. I was trying to use the $reveal widget, like so:

<$reveal type=match state=!!author text=<<currentTiddler>>

Works and Publications: <$list filter="[tag[Fount]search:author[<<currentTiddler>>]!sort[year]]">
<$link to=<<currentTiddler>>><<currentTiddler>></$link>,

</$reveal>

The problem I’m running into is that I don’t know how to get the $reveal widget to search for other tiddlers with a field containing the <<currentTiddler>>. Will the $reveal widget even work for this, or do I need to find another workflow?

Thanks!

1 Like

Welcome CosmicMoth!

Give this a try:

First, create a tiddler (e.g., “ShowWorks”), containing:

<$set name="items" filter="[tag[Fount]contains:author{!!title}]">
<$list filter="[<items>!match[]]">
   Works and Publications:<br>
   <$list filter="[enlist<items>] :sort:date:reverse[{!!year}]">
      <$link/> ({{!!year}})<br>
   </$list>
</$list>

Notes:

  • Line 1 gets a list of all tiddlers that are tagged with “Fount” that have an author list field containing the current tiddler’s title.
    • The contains:author[...] filter treats the author field as a list of space-separated items where items containing spaces are enclosed in doubled square brackets (e.g., “[[John Smith]] [[Mary Doe]] [[Fred Flintstone]]”)
    • The kind of brackets surrounding the operand indicate how to process that operand:
      • Square brackets are used for literal text value (e.g., [sometext])
      • Angle brackets are used for variable references (e.g., <somevariable>)
      • Curly brackets are used for tiddler field references (e.g., {!!somefield})
    • The results of the $set widget are stored in the items variable as a space-separated list with doubled square brackets surrounding any individual items that contain spaces.
  • Line 2 works as a conditional (“if”) so that the output is only displayed if there are matching “Fount” tiddlers
  • Line 3 shows a heading “Works and Publications”
  • Line 4 loops over all items, sorted by date (newest first), based on the !!year field of each tiddler
  • Line 5 shows the link and year for each matching item
    • Note the use of the “short form” of the $link widget, which defaults to using the <<currentTiddler>> value for both the target ("to") parameter as well as the text to display for that link
  • Line 6 marks the end of the loop
  • Line 7 marks the end of the conditional

To use this for a given tiddler:

  • Create a “Person” tiddler (e.g., “John Smith”)
  • Somewhere in the text of the tiddler, enter {{||ShowWorks}}

Notes:

  • The {{||ShowWorks}} syntax “transcludes” the “ShowWorks” tiddler content. The leading || in front of the tiddler title indicates that the transclusion is applied as a “template”, where the content comes from the indicated tiddler, but any field references in that tiddler come from the tiddler that contains the transclusion syntax.

Alternatively, rather than manually entering {{||ShowWorks}} into each tiddler, you can automatically transclude the “ShowWorks” tiddler into each tiddler tagged with “Person” by making the “ShowWorks” tiddler a custom ViewTemplate, like this:

  • Add tag $:/tags/ViewTemplate to the “ShowWorks” tiddler
  • Add this line at the top of the “ShowWorks” tiddler:
    <$list filter="[<currentTiddler>tag[Person]]">

Notes:

  • The $:/tags/ViewTemplate tag indicates that the “ShowWorks” tiddler should be automatically added to the “view mode” display of every tiddler. By default, the content of “ShowWorks” will appear immediately following any body text content of each tiddler.
  • The added $list widget acts as a conditional so that the remainder of the “ShowWorks” content will only be rendered if the current tiddler is tagged with “Person”.

Let me know how it goes…

enjoy,
-e

8 Likes

This is such a wonderful answer: full of details but easy to follow!

I really like the workflow of starting ViewTemplates as a template transclusion. I’ve been creating a lot of ViewTemplates, and if I get my outer list filter wrong, it can wreak havoc. Your style will let me focus on getting the content right first and then making sure it’s applied appropriately later.

While I’ve done something like that by including the eventual ViewTemplate code in a targeted tiddler, there’s too much cut-and-paste to check various conditions. This will help me a lot! I hope it helps the OP as well; it certainly looks like it should.

Thank you!

1 Like

Very useful solution and worth to be under Tips and Tricks.

This worked, thank you so much! Your line-by-line explanation is very informative–I appreciate it a lot.

One other question for you, if it isn’t too much trouble. Is there any way to get the technique that you just explained to work as a part of a view template for a specific type of tiddler (in my case, tiddlers tagged People)?

Cheers!

It seems what you’re asking is exactly what was answered already in this part of the reply by @EricShulman:

… except that you’re using the plural People tag rather than the Person tag that was assumed above.

If that’s not what you’re looking for, could you explain more?

1 Like

You’re absolutely right; I misread the initial reply. Thanks for clearing that up!