View Template for tiddlers that appear in a particular field of any tiddler

I wanted to apply a view template to all tiddlers that appear in a field ‘related’ of any tiddler. So, I wrote the following in a tiddler named ‘ViewTemplateRelated’ and tagged it with ‘$:/tags/ViewTemplate’

<$list filter="[all[current]get[related]enlist-input[]unique[]!is[missing]sort[]]">
  Hello World
</$list>

The tiddlers that appear in the ‘related’ field of several tiddlers are unaffected. But several other tiddlers display Hello World!

What has gone wrong? How do I set it right?

By the way,

<$list filter="[get[related]enlist-input[]unique[]!is[missing]sort[]]">
  <$link />
</$list>

works as expected.

I had a solution (below), but then realized I didn’t understand the question.

There are two aspects to your request.

  1. Which tiddlers activate the view Template
  2. What tiddlers appear when the view template is active

Sometimes the way to deal with this is to nest the list widgets.

Your first version would only activate, if at all, if the current tiddler has a related field. But I don’t think that’s what you want.

Your 2nd version will run at the bottom of every single tiddler. Is that what you want? I don’t think so, but am not sure.

The following solution will only work inside tiddlers that are referenced somewhere inside a related field:

<$list filter="[all[tiddlers]contains:related<currentTiddler>limit[1]]">
  Hello World
</$list>
1 Like

@Mark_S Thanks. Here are answers to the points you have mentioned.

  • A has X and Y in ‘related’ field.
  • B has X and Z in ‘related’ field.

Now,

  • When I look at X, I want to see ‘This is related to A and B’ in the body.
  • When I look at Y, I want to see ‘This is related to A’ in the body.

Hope this makes it clear.

@Mark_S , this worked perfectly! I need to now cook up the code that will pull the list of tiddlers where the current tiddler appears in the ‘related’ field.

@Mark_S Here is another problem now.

This code:

<$list filter="[contains:related<currentTiddler>]">
  <$link />
</$list>

works perfectly when inserted in a tiddler. But when used in the view template like so:

<$list filter="[all[tiddlers]contains:related<currentTiddler>limit[1]]">
  <$list filter="[contains:related<currentTiddler>]"> <$link /> </$list>
</$list>

it fails.

How do I set this straight?

Based on your prior example, I think you want

<$list filter="[all[tiddlers]contains:related<currentTiddler>sort[]]">
   <$link /> 
</$list>
1 Like

@Mark_S Exactly! Thanks a lot. That worked perfectly.