Create tiddler with tags from variable

239 views
Skip to first unread message

Ed Heil

unread,
Jun 3, 2021, 11:53:39 AM6/3/21
to TiddlyWiki
Hello,

I've been trying to do something that seems like it should be simple but maybe isn't.

I'm in a tiddler called "Three Word Title."

I wish to add a tiddler tagged with its name and one other tag, in response to hitting a button.

I would think I'd use something like:

<$action-createtiddler $base="MyBase" tags={{{ [<currentTiddler>] [[OtherTag]] +[join[ ]] }} />

But of course that won't work, it will give it the tags "Three" "Word" "Title" and "OtherTag."

Is there a bulletproof way to turn a list of tiddlers (returned by a filter) into a list with proper [[]] so it's suitable for use in a tags field?

I could do this by creating the tiddler first, then saving the title, then sending a tm-add-tag message, but at that point I need a FieldManglerWidget and it just seems like this ought to be easier.

I thought that maybe enlist or enlist-input should do the job but they don't seem to.

I guess another way of summing up my problem would be that I want this:

<$vars barBaz="bar baz">
"<$text text={{{ [[foo]] [<barBaz>] +[what operator do I want here?[]]  }}}/>"
</$vars>

to somehow produce

"[[foo]] [[bar baz]]"


Darth Mole

unread,
Jun 3, 2021, 12:57:34 PM6/3/21
to TiddlyWiki
Hello,

I know this doesn't get you exactly what you are looking for but I thought it may help. There is a toolbar option "new here" (shown below) that can be turned on that creates a new tiddler with the name of the current tiddler as a tag. However, as you point out with the tm-add-tag situation the option "new here" option doesn't show when editing, only when viewing the tiddler/post save.

Screenshot from 2021-06-03 12-53-27.png

Sorry if the above setting is the exact same thing as the tm-add-tag scenario you mentioned.

Mat

unread,
Jun 3, 2021, 1:04:09 PM6/3/21
to TiddlyWiki
Seems to work:

\define t() [[$(currentTiddler)$]] OhterTAG

<$button>
<$action-createtiddler $basetitle="MyBase" tags=<<t>> />
x
</$button>


<:-)

Darth Mole

unread,
Jun 3, 2021, 2:19:24 PM6/3/21
to TiddlyWiki
Mat, where would you put your code so that it was available while editing a tiddler?

Mat

unread,
Jun 3, 2021, 3:33:23 PM6/3/21
to TiddlyWiki
Mat, where would you put your code so that it was available while editing a tiddler?

Hm, in edit mode? OK, you could try to put it in a tiddler that you tag "$:/tags/EditTemplate" (and click that very tag to reorder where it is positionend). You might have to edit the current tiddler or it will probably be the Draft ending up as the tag. I'm about to go out so can't check exactly which filter operator that is to get the "non Draft" but it's there... 

<:-) 

Darth Mole

unread,
Jun 3, 2021, 5:50:38 PM6/3/21
to TiddlyWiki
Yea, unfortunately I think this is beyond me at the moment. Thanks for the information though!

TW Tones

unread,
Jun 3, 2021, 6:37:15 PM6/3/21
to TiddlyWiki
Mats Suggestion is simple. 

Create a tiddler and insert his code
Add the tag  $:/tags/EditTemplate" or "$:/tags/ViewTemplate" to place it on the edit and/or view template

This is your introduction to making solutions that apply across all tiddlers. TiddlyWiki has a rich set of features to do what you are asking, this is the main method.

Tones

Darth Mole

unread,
Jun 3, 2021, 7:53:46 PM6/3/21
to TiddlyWiki
It would seem that I was somehow confusing myself earlier as when I reread Mat's instructions, after your reply TW, it seemed to click and I was able to get it working minus the "Draft of"  I just have three additional questions:

1) Why am I tagging the Tiddler that has the code with /tags/EditTemplate and not core/ui/EditTemplate as the others are listed when I'm reordering the tags?
2) I originally tried pasting Mat's code into the custom edit area of Stroll, which also uses the /tags/EditTemplate tag but the define line wouldn't activate. Given that both tiddlers follow the same instructions is there a reason why one worked and one didn't? The only difference was the existence of two other tags and some instructions already in the body of the tiddler.
3) Is there a specific place on the TiddlyWiki website where the above information is described? When I was attempting to troubleshoot the \define line not working I was having a heck of a time trying to follow what was written so I'm curious if I was looking in the wrong place.

Thank you!

Mat

unread,
Jun 4, 2021, 10:09:24 AM6/4/21
to TiddlyWiki
1) Why am I tagging the Tiddler that has the code with /tags/EditTemplate and not core/ui/EditTemplate as the others are listed when I'm reordering the tags?

The $:/tags/EditTemplate is the common tag for all edittemplates. When you click that tag you see all tiddlers tagged such. They are typically tiddlers titled $:/core/ui/something because they are part of the core TW plugin. Your tiddler is not part of the core plugin so you can call it whatever you want (also with or without a prefixing $:/ )
 
2) I originally tried pasting Mat's code into the custom edit area of Stroll, which also uses the /tags/EditTemplate tag but the define line wouldn't activate. Given that both tiddlers follow the same instructions is there a reason why one worked and one didn't? The only difference was the existence of two other tags and some instructions already in the body of the tiddler.

All pragmas, i.e all commands with a prefixing \ character, must be grouped at top of tiddler. If you study some system tiddlers, you'll understand what is meant with this. That could be one reason why your attempt didn't work. Another thing is that e.g a \define can be a single row or it is a multirow that ends with an \end marker. Again, check out some macros or similar and you'll get the idea.
 
3) Is there a specific place on the TiddlyWiki website where the above information is described? When I was attempting to troubleshoot the \define line not working I was having a heck of a time trying to follow what was written so I'm curious if I was looking in the wrong place.

Yes, again, all \ prefixed stuff are called pragmas. You are specifically concerned with macros here, i.e the thingies that are created with a \define pragma (and that often end with  \end )

As for getting the original name of a tiddler when you're in edit mode, I thought there should be some filter op for this (is[draft]) but maybe I'm wrong. Anyway, you should be able to do this to get the non-draft title when you're in the draft: 

\define t() [[$(nondraft)$]] OhterTAG

<$vars nondraft={{{ [<currentTiddler>removeprefix[Draft of ']removesuffix[']] }}} >
<$button><$action-createtiddler $basetitle="MyBase" tags=<<t>>/> </$button>
</$vars>

<:-)
 

Ed Heil

unread,
Jun 4, 2021, 12:49:38 PM6/4/21
to TiddlyWiki
Mat's initial suggestion worked great.  I didn't need this to appear everywhere, or in edit mode.  Just in a certain class of tiddlers which are already being displayed through a special template (which is where this button will appear).

Thanks, everyone!

TW Tones

unread,
Jun 5, 2021, 10:11:47 PM6/5/21
to TiddlyWiki
I will just add if you \define something() and leave it empty it will break things

Tones

Ed Heil

unread,
Jun 17, 2021, 10:00:32 AM6/17/21
to TiddlyWiki
Just a note -- there is a straightforward way to get tiddler titles automatically bracketed, which I discovered eventually.

<$set name="myTags" filter=" [<currentTiddler>] [[OtherTag]]">
<$action-createtiddler $base="MyBase" tags=<<myTags>> />
</$set>

A SetWidget with "Filtered List Variable Assignment" automatically double-brackets items in the list provided to it.

Reply all
Reply to author
Forward
0 new messages