Conditionally trigger action-createtiddler using a List Widget

99 views
Skip to first unread message

Lisa Wasserman

unread,
May 27, 2020, 10:54:55 PM5/27/20
to TiddlyWiki
I'm still trying to automatically create a new tiddler if one of the required title doesn't exist.  My existing code is as follows:

\define journalTiddlerName( ) $(when)$ $(project)$
\define state() $:/state/$(currentTiddler)$
\define createTodaysEntry()
<$action-createtiddler $basetitle=<<journalTiddlerName>> tags="journal $(project)$" project=$(project)$ description="$(description)$" />
\end

<$vars project={{!!project}} description={{!!description}} when=<<now DD-MMM-YYYY>> >
<$list filter="[title<journalTiddlerName>] +[is[missing]] +[limit[1]]">
<<createTodaysEntry>>
</$list>
</$vars>

While I could get the list widget to display different strings, dependent on whether the tiddler existed, I could not create a new tiddler.  After a little reading, it seems that Action Widgets need to be triggered specially.  Is there a simple method that I can use to trigger my action-createtiddler, inside of my list widget?  I don't want to have to press a button, when I always want to create a tiddler if it doesn't already exist.


TonyM

unread,
May 27, 2020, 11:57:38 PM5/27/20
to TiddlyWiki
Lisa

Quick tip: Wrapping even a list that contains actions widgets with a button is sufficent to trigger that action for every item in the list.

\define journalTiddlerName( ) $(when)$ $(project)$
\define state() $:/state/$(currentTiddler)$
\define createTodaysEntry()
<$action-createtiddler $basetitle="$(journalTiddlerName)$" tags="journal $(project)$" project=$(project)$ description="$(description)$" />

\end

<$vars project={{!!project}} description={{!!description}} when=<<now DD-MMM-YYYY>> >
<$button>

<$list filter="[title<journalTiddlerName>] +[is[missing]] +[limit[1]]">
<<createTodaysEntry>>
<
/$list>
Create <<journalTiddlerName>>
</
$button>
</$vars>


Note that I changed the reference to 
$basetitle="$(journalTiddlerName)$"

Perhaps you could add 

FYI when you use a value in the current tiddler to create a new one with the same values such as project I have started calling this "in context", I plan to release a "context tool" one day.

Regards
Tony

Michael Manti

unread,
May 28, 2020, 8:08:53 AM5/28/20
to TiddlyWiki
TonyM,

What role does the state macro play? I don't see it called anywhere.

Thanks!

Mike

Lisa Wasserman

unread,
May 28, 2020, 10:07:59 AM5/28/20
to TiddlyWiki
It was part of the larger chunk of code that I was working on.  I separated this piece out, trying to get it to work.

Michael Manti

unread,
May 28, 2020, 12:09:04 PM5/28/20
to TiddlyWiki
Ah! Thanks for clarifying.

Lisa Wasserman

unread,
May 28, 2020, 5:31:23 PM5/28/20
to TiddlyWiki
Thank you!  That solved it nicely.  I already had a button that allowed me to switch between editing and viewing the tiddler.  I moved the list inside of the macro, then put the macro call inside of the button that put the tiddler into edit mode.  Here's what I ended up with:

\define journalTiddlerName( ) $(when)$ $(project)$
\define state() $:/state/$(currentTiddler)$
\define createTodaysEntry()
<$list filter="[title[$(journalTiddlerName)$]] +[is[missing]] +[limit[1]]">
<$action-createtiddler $basetitle="$(journalTiddlerName)$" tags="journal $(project)$" project=$(project)$ description="$(description)$" />
</$list>
\end

<$vars project={{!!project}} description={{!!description}} when=<<now DD-MMM-YYYY>> filterwhen=<<now YYYY0MM0DD0hh0mm>>>
<$reveal type="nomatch" state=<<state>> text="show">
<p><h1>Today <$button set=<<state>> setTo="show" class="tc-btn-invisible" style="fill:#00aaaa;">{{$:/core/images/edit-button}}<<createTodaysEntry>></$button></h1></p>
<p><$transclude tiddler=<<journalTiddlerName>> mode="block" /></p>
</$reveal>
<$reveal type="match" state=<<state>> text="show">
<p><h1>Today <$button set=<<state>> setTo="hide" class="tc-btn-invisible" style="fill:#00aaaa;">{{$:/core/images/done-button}}</$button></h1></p>
<p><$tiddler tiddler=<<journalTiddlerName>>>{{||$:/core/ui/EditTemplate/body/editor}}</$tiddler></p>
</$reveal>
</$vars>


TonyM

unread,
May 28, 2020, 8:06:14 PM5/28/20
to TiddlyWiki
Great,

Using buttons as a trigger around otherwise complex lists containing action widgets is a powerful code pattern to learn.

Its a good way to make buttons to do batch changes on tiddlers, this allows one to redesign your wiki. Like using tags to set a field then delete the tag as one example.

Regards
Tony
Reply all
Reply to author
Forward
0 new messages