SetWidget inside Macro

115 views
Skip to first unread message

Matthew DeAbreu

unread,
May 31, 2017, 6:59:08 PM5/31/17
to TiddlyWiki
Hello!

I've been using TW5 on and off for quite a while and I've recently decided to use it for taking notes/tasks while working. As part of this I'd like to have a quick and easy way to create tiddlers with a given prefix (based on tags) and a name. I haven't done much in the way of customizing TW5 before so most of this is quite new, any help/suggestions would be appreciated.

For example:
If I have a tiddler titled "PR123456 Tasks" tagged with "PR123456 [[PR Tasks]]" I would like to have a text edit field that will take the task name and produce a tiddler titled "PR123456 Task: task-name-here".

Here's some sample code:


\define concat(word1 word2)
$word1$ $word2$
\end


\define createTaskTiddler(prefix tags)
<$edit-text tiddler="$:/state/new-task-title" tag="input" default="" placeholder="Task Title"/>
<$button>
<$vars name={{$:/state/new-task-title!!text}}>
<$action-createtiddler $basetitle="$prefix$$(name)$" tags="$tags$" completed="false"/>
</$vars>
<$action-deletetiddler $tiddler="$:/
state/new-task-title"/>
<$action-sendmessage $message="
tm-auto-save-wiki"/>
Add Task
</$button>
\end


<$list filter="
[is[current]tags[]]+[!tag[PR Tasks]]">
<$set name="
prNum" value=<<currentTiddler>>>
<$set name="
prefix" value=<<concat $(prNum)$ "Task: ">>>


<<createTaskTiddler $(prefix)$ "
$(prNum)$ Task">>


</$set>
</$set>
</$list>


You can view a semi working demo here: https://tw.mdeabreu.com/work.html#PR123456%20Tasks
When you try it you should be able to see that when you attempt to add a new task the tiddler created has the title "PR123456 Tasks: " but it is failing to transclude the title.

Any tips, help, and suggestions would be greatly appreciated.

Thanks!

Mark S.

unread,
May 31, 2017, 8:31:36 PM5/31/17
to TiddlyWiki
Your code changed a bit. I don't have time to explain what I did, but if you experiment with this it should help:

Macro: createTaskTiddler


\define basetitle() $(p1)$ Task: $(p2)$
\define createTaskTiddler()

<$edit-text tiddler="$:/state/new-task-title" tag="input" default="" placeholder="Task Title"/>
<$button>
<$vars p2={{$:/state/new-task-title!!text}} p1="$(curTag)$" >
<$action-createtiddler $basetitle=<<basetitle>> tags="$(curTag)$" completed="false"/>

</$vars>
<$action-deletetiddler $tiddler="$:/
state/new-task-title" />
<$action-sendmessage $message="
tm-auto-save-wiki"/>
Add Task
</$button>
\end


Template file (I took out the new sections you had added in order to concentrate on the naming code, but you can paste those back in):


<$list filter="[is[current]tag[PR Tasks]]">


<$set name="curTask" value=<
<currentTiddler>>>


<$list filter="[is[current]tags[]]+[!tag[PR Tasks]]">
<$set name="curTag" value=<<currentTiddler>>>

<
<createTaskTiddler>>


</$set>
</$list>
</$set>

</$list>

Quickly, $(var)$ and $var$ only work INSIDE a macro. They also only work when called from a prior macro (not inside the current macro). So if you define a variable and want to use it immediately, you have to invoke it like <<myvarname>>.


Good luck,
Mark

Matthew DeAbreu

unread,
Jun 1, 2017, 1:57:07 AM6/1/17
to TiddlyWiki
Hey Mark,

Just tried it out and everything worked perfectly! Did a little bit of tweaking and things are well on their way to completion.

Thank you so much for the rapid and thorough response!
Reply all
Reply to author
Forward
0 new messages