Change currentTiddler within macro based on macro input

42 views
Skip to first unread message

David Allen

unread,
Dec 21, 2019, 2:32:31 PM12/21/19
to TiddlyWiki
I do not want a new plugin, so please don't suggest one!
I have a macro as follows:

\define img_gallery2(target_tiddler)
<div style="width: 33%; float: right;">
<<single_image3>>
<<add_gallery2>>
</div>
\end

Right now, target_tiddler is not used.  single_image3 and add_gallery2 both use text references for the currentTiddler variable (such as {{!!images}} ).

I want to expand this macro to set currentTiddler to the value of target_tiddler only if target_tiddler is defined, but leave it alone otherwise.

Anyone have any suggestions?
I do not want a new plugin, so please don't suggest one!

bimlas

unread,
Dec 21, 2019, 2:43:02 PM12/21/19
to TiddlyWiki
David Allen,

I think you need to use the Tiddler widget (https://tiddlywiki.com/#TiddlerWidget):

\define img_gallery2(target_tiddler)
 
<$tiddler tiddler=<<__target_tiddler__>>>

   
<div style="width: 33%; float: right;">
     
<<single_image3>>
     
<<add_gallery2>>
   
<
/div>
  </
$tiddler>
\end

Mark S.

unread,
Dec 21, 2019, 3:20:06 PM12/21/19
to TiddlyWiki
Try

\define img_gallery2(target_tiddler)
<$list filter="[<__target_tiddler__>!is[missing]] ~[title<currentTiddler>]">

<div style="width: 33%; float: right;">
<<single_image3>>
<<add_gallery2>>
<
/div>
</
$list>
\end


David Allen

unread,
Dec 21, 2019, 3:27:36 PM12/21/19
to TiddlyWiki
Thank you! This is working now.  I didn't know the exact syntax for doing <<__parameter__>> inside a filter, so that helped.

Also, why is the ~ in front of the title<currentTiddler> again?

Mark S.

unread,
Dec 21, 2019, 3:37:22 PM12/21/19
to TiddlyWiki


On Saturday, December 21, 2019 at 12:27:36 PM UTC-8, David Allen wrote:

Also, why is the ~ in front of the title<currentTiddler> again?


That means "else". So if the first run doesn't find the target tiddler, the second run will use the current tiddler.
Reply all
Reply to author
Forward
0 new messages