Looking for Some Working Examples: Modifier Key

Within the action string of the DroppableWidget, the action string of the ButtonWidget and the action string of the LinkCatcherWidget and the EventCatcherWidget, the modifier variable contains the modifier key(s) held during the drag-process.

See: Modifier Variable

Here’s an example that uses $droppable to create a tiddler with either an external link or an iframe, depending upon whether the CTRL key modifier is held down when dropping a URL on the target.

\define make_link() [ext[$(actionTiddler)$]]
\define make_iframe() <iframe src="$(actionTiddler)$" style="width:100%;height:70vh;"></iframe>

\define drop_actions()
<$action-createtiddler $basetitle=<<actionTiddler>>
   text={{{ [<modifier>match[ctrl]then<make_iframe>else<make_link>] }}}/>
\end

<$droppable actions=<<drop_actions>>>
   <span title="drop URL here to create a bookmark (hold CTRL to create an iframe)">
   {{$:/core/images/link}}
   </span>
</$droppable>
5 Likes

Many thanks Eric!
So, I can use the same logic for buttongWidget!

I was able to use the same logic with Button widget!

\define btnActions() 
<$let
   createTask='<$action-sendmessage $message="tm-new-tiddler" title=<<unusedtitle "New Task">> tags="Task" due-date="2021-12"/>'
   gotoTasks ='<$action-navigate $to="Tasks Explorer" $scroll=yes/>'
   actions={{{ [<modifier>match[ctrl]then<gotoTasks>else<createTask>] }}}
>
  <<actions>>
</$let>
\end

<$button actions=<<btnActions>> > Create Task</$button>
  • the above code creates a task tiddler if button clicked
  • it opens the Tasks Explorer tiddler if button ctrl+clicked
  • this solution uses the new $let widget in Tiddlywiki 5.2.1
2 Likes