Advice on procedures and templates

Hi,
I’m new to TiddlyWiki, please let me know if this is not an appropriate post.

I am experimenting with programmatically creating new Tiddlers for a Project management system. I’d like to have two buttons

  1. In a Projects Tiddler a New Project button that generates a project Tiddler that includes
  2. A button that creates a new task tagged with that project

I would appreciate some feedback on my approach. This is what I got

The project template tiddler called NewProjectParam

\define newProjTaskActionWidget(title)
<$action-sendmessage
    $message="tm-new-tiddler"
    title="New Task"
    tags="[[task]] [[$title$]]"
		priority="Z"
		/>
\end

\procedure toButton()
	<$transclude $variable="newProjTaskActionWidget" title={{!!title}}/>
\end

!! TOC


<$list filter="[all[current]tagging[]!tag[Meeting]!tag[task]sort[title]]">
<<currentTiddler>><br>
</$list> 


!!! Meetings

<$list filter="[all[current]tagging[]tag[Meeting]!sort[created]]">
<<currentTiddler>> ({{!!at}})<br>
</$list> 

!!! Tasks



<$button actions=<<toButton>>>New Task</$button>



<<list-tagged-draggable tag:"task" subFilter:"all[current]tagging[]tag[task]!has[draft.of]!tag[done]sort[priority]" itemTemplate:"TemplTask" emptyMessage:"You don't have any active tasks">>

<$list filter="[!has[draft.of]all[current]tagging[]tag[task]tag[done]sort[modified]]">
<div>
<$checkbox tag="done"> ~~<$link/>~~</$checkbox>
</div>
</$list>

Than in Project I have

\define newProjectActionWidget()
<$action-sendmessage
    $message="tm-new-tiddler"
		$param="NewProjectParam"
    title="New Project"
    tags="[[Project]]" />
\end

<$button actions=<<newProjectActionWidget>>>New Project</$button>

<<list-links "[tag[Project]sort[title]]">>

TemplTask is very simple:

<$checkbox tag="done"> <$link/> {{!!priority}}</$checkbox>

It seems to work fine but I am not sure about the procedure and definition. Any feedback is highly appreciated! Thanks!

1 Like

I also added a New Meeting button that links to the current date (in the format I have set up my Journal):

\define newProjMeetingActionWidget(title, at)
<$action-sendmessage
    $message="tm-new-tiddler"
    title="New Meeting"
    tags="[[Meeting]] [[$title$]]"
		at=[[$at$]]
/>
\end

\procedure toButtonMeetingAction()
	<$transclude $variable="newProjMeetingActionWidget" title={{!!title}} at={{{[{!!modified}format:date[YYYY-0MM-0DD]]}}}/>
\end

<$button actions=<<toButtonMeetingAction>>>New Meeting</$button>

This also summarizes my question. Is the define - procedure /$transclude - $button combination a robust definition? Are there easier ways?

Hi Daniel – Welcome!

Every post, that is according to the forum rules is appropriate.

IMO it’s better to ask questions frequently, than to “bang your head against a wall”, because it sometimes works differently as expected :wink:

have fun!
-mario

2 Likes

Welcome to the forum @danielw2904 what is interesting is that you are starting to leverage new TW 5.3.0 features. Whilst I am a “super user” as opposed to “Developer” I have tried and true methods devloped prior to 5.3.0 and only now evaluating the best approaches using the new features. To allow some evaluation of your methods now perhaps I just add a few notes;

  • If you are going to use 5.3.0 Features, you may as well concider avoiding using the earler methods such as \define.
  • If you use 5.3.0 features they will not work on earlier wiki versions, not a big issue as they can be upgraded.
    • In these forums there is already a lot of discussions using the pre 5.3.0 methods for new tiddler buttons which remain valid.
  • I often made use of the createtiddler widget, as it has more options than the tm-new-tiddler message.
  • There is an Unused title macro if you want
  • Its wise to move commonly used macro definitions into a tiddler with the $:/tags/Macro tag to make them global, then use a tiddler with the $:/tags/ViewTemplate tag to display on all tiddlers, but then wrap your project handling buttons in a condition to only appear on project tiddlers.
<$list filter="[all[current] is project filter " variable=~>

all project code here

</$list>
  • Note the use of variable=~ so as not to change currentTiddler.
  • I see you are using <$transclude $variable which is the modern form of the macrocall widget, which is in effect a proceedure call, yet you call a macro defined by \define.
    • It would be wise to refactor newProjMeetingActionWidget as a procedure.
  • In some ways I can’t see a template (in the title of this topic) in use in your code, more like a button to create particular tiddlers.
  • What you are doing is a common function, creating a new tiddler of different types, that also inherits a context, in this case the project.
    • It would be nice if we had some supporting macros already for users to create such tiddlers, but it does get a little complex trying to meet all possible needs.
1 Like

Thank you @pmario and @TW_Tones for the warm welcome and the great advice. Lots to think about! I started using TW just a couple of days before 5.3.0 was released so I figured I might as well get started with the new features (but as you noted I am not 100% clear on what is a new feature yet).

I’m going to try to refactor and document here for future reference.

You can see everything in the new release here Releases and will see this on the documentation Snag_1b84559

We are a helpful bunch so feel free to ask. But it always helps if you;

  • Try your self first but;
  • Ask for what you want to achive rather than describe half a solution that’s not working.

@danielw2904

Thanks for your kind efforts and input. I tried your extension New Meeting, but it does not work in 5.3.0.

Best regards, Bapak Ireng

Very strange. I am on 5.3.0 and it works for me. Unfortunately I have no idea how to debug.

I made some progress in implementing this fully (I hope) using 5.3.0 features. Does the following work for you?

\procedure newTask()
	<$action-sendmessage
			$message="tm-new-tiddler"
			title="New Task"
			tags=`[[task]] [[$(currentTiddler)$]]`
	/>
\end

\procedure newMeetingCore(at)
	<$action-sendmessage
			$message="tm-new-tiddler"
			title="New Meeting"
			tags=`[[Meeting]] [["$(currentTiddler)$"]]`
			at=`[[$(at)$]]`
	/>
\end

\procedure newMeeting()
	<$transclude 
		$variable="newMeetingCore" 
		at={{{[{!!modified}format:date[YYYY-0MM-0DD]]}}}/>
\end


<$button actions=<<newTask>>>
New Task
</$button>

<$button actions=<<newMeeting>>>
New Meeting
</$button>

This version works like a charm. :+1:

1 Like

Thank you again for your great suggestions! I (think I) managed to refactor to 5.3.0 features (see above) and moved definitions to $:/tags/Macro tagged Tiddlers (this is great!).

Could you please elaborate on:

In which cases is variable=~ used? How would it change if that is not used?

By default, when variable=... is NOT used, the $list widget sets the value of currentTiddler, so that references to <<currentTiddler>> can be used inside the body content of the $list widget.

By using variable="something" it sets the value of something instead of currentTiddler, which allows you to preserve the existing value of currentTiddler within the body content of the $list widget.

In @TW_Tones example code, he uses “variable=~”, but you could also use any other name, such as variable=none (my preference) or variable=arglebargle to accomplish the same effect.

1 Like

Finally also figured out that point. I refactored to:

  1. The project template (also using tables to render known types of tiddlers now)

!! TOC


<$list filter="[all[current]tagging[]!tag[Meeting]!tag[Task]sort[title]]">
<<currentTiddler>><br>
</$list> 


!!! Meetings


<$button actions=<<procNewMeeting>>>
New Meeting
</$button>

<table>
  <tr>
    <th>Meeting</th>
		<th>Date</th>
		<th>Summary</th>
  </tr>
	<$list filter="[!has[draft.of]tag<currentTiddler>tag[Meeting]] :sort:date:reverse[get[at]else[modified]]">
  <tr>
    <td>{{!!title}}</td>
		<td>{{!!at}}</td>
		<td>{{!!summary}}</td>
  </tr>
	</$list>
</table>

!!! Tasks


<$button actions=<<procNewTask>>>
New Task
</$button>

<table>
  <tr>
    <th>Task</th>
		<th>Tags</th>
		<th>Priority</th>
  </tr>
	<$list filter="[!has[draft.of]tag<currentTiddler>tag[Task]!tag[blocked]!tag[done]sort[modified]sort[tags]] :sort:string[get[priority]else[Z]]">
  <tr>
    <td>
			<$checkbox tag="done"> 
				<$link/>
			</$checkbox>
		</td>
		<td>{{!!tags}}</td>
		<td>{{!!priority}}</td>
  </tr>
	</$list>
</table>



<$list filter="[!has[draft.of]tag<currentTiddler>tag[Task]tag[done]sort[modified]]">
<div>
<$checkbox tag="done"> ~~<$link/>~~</$checkbox>
</div>
</$list>

And a button in my dasboard that creates a new project and edits it

<$button>
<$action-createtiddler $basetitle="New Project" tags="[[Project]]" $template="templateNewProject">
<$action-sendmessage $message="tm-edit-tiddler" $param=<<createTiddler-title>>/>
</$action-createtiddler>
New Project
</$button>