Help need to make a viewtoolbar button to modify current-tiddler field of $:/HistoryList tiddler

https://demo-hub.tiddlyhost.com/#%24%3A%2Farsheth%2Fcard-ui%2Fbuttons%2Ffocus-card

\procedure focus-card()
<% if [$:/HistoryList]get[current-tiddler]!match<currentTiddler>]  %>
<$action-setfield $tiddler="$:/HistoryList"  current-tiddler=<<storyTiddler>>/>
<$action-navigate $to=<<storyTiddler>>/>
<% elseif [$:/HistoryList]get[current-tiddler]match<currentTiddler>] %>
<$action-deletefield $tiddler="$:/HistoryList" $field="current-tiddler"/>
<% else %>
<$action-deletefield $tiddler="$:/HistoryList" $field="current-tiddler" />
<% endif %>
\end

<$button actions=<<focus-card>> class=<<tv-config-toolbar-class>>>
{{$:/images/remix-icon/design/focus-3-line}}</$button>

Here I am trying to create a viewtoolbar button to set the storyTiddler as the field-value of the current-tiddler field of $:/HistoryList tiddler (as part of one of my custom UI). On the second click I want to remove the current-tiddler field from $:/HistoryList tiddler so as to change the currrentTiddler

The first step is working, but the second one is not. Can someone help.

It looks like you’re missing a [ from the beginning of each if filter. I haven’t tested the rest of it, but I’m sure that’s not helping!

3 Likes

Thank you @etardiff for pointing to the missing [. That helped me to do more testing and finally got this code working

\procedure focus-card()
<% if [[$:/HistoryList]get[current-tiddler]!match<storyTiddler>]  %>
<$action-setfield $tiddler="$:/HistoryList"  current-tiddler=<<storyTiddler>>/>
<$action-navigate $to=<<storyTiddler>>/>
<% elseif [[$:/HistoryList]get[current-tiddler]match<currentTiddler>] %>
<$action-deletefield $tiddler="$:/HistoryList" $field="current-tiddler"/>
<% elseif [[$:/HistoryList]!has[current-tiddler]]%>
<$action-setfield $tiddler="$:/HistoryList"  current-tiddler=<<storyTiddler>>/>
<$action-navigate $to=<<storyTiddler>>/>
<% endif %>
\end

<$button actions=<<focus-card>> class=<<tv-config-toolbar-class>>>
{{$:/images/remix-icon/design/focus-3-line}}</$button>

What you are asking is I believe setting the current tiddler in the wiki, I called this the last focused tiddler in my “focused tiddler solution” however this is also achieved by navigating to that tiddler.

  • You can possibly just take the button $:/PSaT/focus-tiddler/button and a few other tiddlers, let me see if I can package it.

So you may be able to simplify this using the ActionNavigateWidget

Post Script,

I packaged my focus button here simple-focus.json (4.6 KB)
and tested on tiddlywiki.com

1 Like

Thanks @TW_Tones for your focus tiddler json. I had previously used it my wikis. But my current usecase is changing the width and height of the current tiddler in custom story river ( seen as a grid of cards) using a viewtoolbar button and keyboard shortcuts. For that, this small code to access the current-tiddler field of historylist tiddler is sufficient.