How can I determine if a tiddler is being viewed by through a template?

I have:

  • Tiddler A
  • TIddler B
  • Template

Tiddler A looks like this:

{{Tiddler B||Template}}

Tiddler B will a field that may or may not be present. When it’s not present, I need that field from Tiddler A.

How can the Template determine if Tiddler A is viewing Tiddler B and use Tiddler A field if it doesn’t exist?

I have work around to make this work:

<span class="tid-a">
{{Tiddler A||Template}}
</span>

With the CSS:

.alt-a {
  display: none;
}
.tid-a .alt-a {
  display: inline;
}

With Tiddler B looking like:

<span class="alt-a"><$view field="alt-a-fieldname"/></span>

You can use the fall-through feature of nested widgets. If the outer element doesn’t have a value, then the inner element (widget) provides the value. So your template could look like:

<$view field="myfield"><$view tiddler="Tiddler A"  field="myfield"/></$view>

I don’t suppose there is a way to figure out what Tiddler A is dynamically.

Because Tiddler A could be Tiddler C or Tiddler D.

Tiddler A, Tiddler C, or Tiddler D could all be pointing to:

{{Tiddler B||Template}}

Suppose Tiddle A had:

<action-setfield tiddler="$:/temp/mytiddler" field="myfield" value={{!!field}}/>
/*Could I use <$set> or <$vars>? */
{{Tiddler B||Template}}
/*Then I would have to clear that field*/
<action-setfield tiddler="$:/temp/mytiddler" field="myfield" value=""/>

Then Tiddler B would have:

<$view field="myfield"><$view tiddler="$:/temp/mytiddler"  field="myfield"/></$view>

Have you tried the <<transclusion>> variable?

https://tiddlywiki.com/#transclusion%20Variable

I haven’t thought of that, but it does spark an idea.

Tiddler A:

\define parentTiddler()
{{!!title}}
\end

{{Tiddler B||Template}}

Tiddler B:

<$view field="myfield"><$view tiddler=<<parentTiddler>>  field="myfield"/></$view>

I wish I wasn’t working so I could try this.

@RedAsset because you are asking a question halfway through finding a solution you are asking somewhat difficult to answer questions. But let me have a try.

In this shortcut transclusion you are choosing to set the currentTiddler to “Tiddler B”, so at rendering the template uses this. However there is another variable available you can “make use” of so try <<storyTiddler>>.

  • This is the variable for the title used during the rendering of the story river so It will not be available elsewhere like the sidebar.
  • How can I determine if a tiddler is being viewed by through a template? If the storyTiddler and currentTiddler variables do not match?

The above is I believe an answer to your question, but I do think you may be asking the wrong question.

  • This changes depending on how you transclude the “template”.
  • The real question relates to “Using a field in Tiddler B and use Tiddler A field if it doesn’t exist?”. @Mark_S answered this well.
  • What else is in the template or is it only for this question?

Another equivalent to;

Is this

{{{ [all[current]get[fieldname]] :else[[Tiddler A]get[fieldname]] }}}

  • However if using filtered transclusions you may nee to convert it to text. <$text text={{{ filter }}/>

Thanks, <<storyTiddler>> really simplifies things. Once again, I feel like I try to solve a problem with a complex solution when there really is a simple one available.

<$view tiddler=<<storyTiddler>> field="fieldname"/>

Thanks for the help!

No problem,

It happens to us all. The difference in the tiddlywiki community is that is OK, just ask.