Use transclusion result in another widget or macro?

Let’s say I use tiddlywiki for journaling. In my journal tiddlers I have a field called mantra. It can be missing.
I want to stick above the Story River the content of that field for the Journal’s tiddler of today.
I want to use a template for this.

I have a tiddler “Sticky Mantra” tagged $:/tags/AboveStory which diplays on top of the story
I have a template “MantraTemplate” containing {{!!mantra}} to display the concerned field

Let’s say today is the 10th of february 2024 and today’s journal is named 2024-02-10

I can render today’s journal as: {{2024-02-10||MantraTemplate}} in “Sticky Mantra”

I can dynamically retrieve today’s journal title as: <$transclude $variable="now" format={{$:/config/NewJournal/Title}}/>

But I can’t find a way to combine those two.

I know that I can express the template transclusion {{2024-02-10||MantraTemplate}} with the tiddlerWidget:

<$tiddler tiddler="2024-02-10">
  <$transclude tiddler="MantraTemplate"/>
</$tiddler>

and I’m feeling that this a way to go, but I tried all my ways and I can’t find how to use the result of the transclusion <$transclude $variable="now" format={{$:/config/NewJournal/Title}}/> as the parameter tiddler of the above.

Am I totally in the wrong or can someone enlight the bit I am missing ?

Use wikify

<$wikify name="variableName" text="""<$transclude $variable="now" format={{$:/config/NewJournal/Title}}/>""">
  <$transclude tiddler=<<variableName>> />
</$wikify>

now you can get variable from anything you want.

As @linonetwo indicated you can use wikify to have some “TiddlyWiki Script” evaluated so you can then make use of it.

However wikify is not recommended due to performance issues, and I personally don’t like the following about wikify;

  • It is verbose and messy code
  • It should be used at the last possible moment.

However there are now better ways to cause evaluation (before the final display/render step), such as if you can get you values from a filter use the new functions, also consider using the new backtick attribute values Substituted Attribute Values, because the variable substitution and filters within that, are evaluated when the parameter is used.

Something that took me a long time to learn, is when you use a widget, that is the last step before displaying content (because it is clumsy to try and use the output of a widget in further logic). Thus, I now think of widgets as “the final display step”, and don’t use them as input to anything.

  • This is only a guide, but the point is as soon as you use a widget, don’t expect its result to be used in later logic outside that widget.
  • This is not as limiting as you may think, consider using nested list widgets, a lot more occurs inside the outer list widget, it’s just that the content within is used within only and the outer list widget is not used as input to anything else.

Hi, I would do it like this:

  • Sticky Mantra contains the template.
  • The Journal tiddler contains the mantra of the day
title: Sticky Mantra
tags: $:/tags/AboveStory

\function getJournalDate() [<now [UTC]YYYY0MM0DD0hh0mm0ss0XXX>format:date{$:/config/NewJournal/Title}]

<$transclude $tiddler=<<getJournalDate>> $field=mantra/>

The Journal by default at tiddlywiki.com looks like this: 12th February 2024

title: 12th February 2024
mantra: mantra of 2024-02-12

So every day the journal tiddler can contain a new mantra: some text, which will be shown above the story.

have fun!
mario

2 posts were split to a new topic: Lingo translation macro and text substitution