Button catching currentTiddler title as tag

In my new TW playground, I use button definitions like this one :

\define SocieteButton()
<$button tooltip='Ajouter une nouvelle société' aria-label='Nouvelle société' >
<$action-sendmessage $message="tm-new-tiddler" $param="$:/.my/template/Société" title="Nouveau Tiddler" tags="Société" />
<$list filter="[<tv-config-toolbar-icons>prefix[yes]]">
{{$:/core/images/new-button}} Société
</$list>
</$button>
\end
<<SocieteButton>>

This is fine, this button creates new tiddler using a template to get specific fields and tags in the new tiddler. I also transclude this button in any tiddler where I need this function.

But now transcluding this button in a tiddler named MyTiddler I would like to set the tag of my new tiddler to the title of MyTiddler as in the NewHere button.
I looked at $:/core/ui/Buttons/new-here but I’m a bit lost in /procedures and set parameters to reverse engineer it…

Any help would be greatly appreciated.

Try the version below. Note tags=<<storyTiddler>> would normally work to pass the name of the enclosing tiddler to the new-tiddler action as a tag, but if your title has spaces in it, you would end up with a tag for each word in the title. The version below uses the titlelist format to ensure using the button inside Hello There would make just a single tag with that string.


\define SocieteButton()
<$button tooltip='Ajouter une nouvelle société' aria-label='Nouvelle société' >
<$action-sendmessage $message="tm-new-tiddler" $param="$:/.my/template/Société" title="Nouveau Tiddler" tags={{{ [<storyTiddler>format:titlelist[]] }}} />
<$list filter="[<tv-config-toolbar-icons>prefix[yes]]">
{{$:/core/images/new-button}} <<storyTiddler>>
</$list>
</$button>
\end
<<SocieteButton>>

Thank you for your solution that works fine! I would never have found this myself.

1 Like

I have a follow-up question. How can I add more tags to the button with this code?

Hello @msone! The answer depends on how you want to add more tags (for the tiddler being created with this button). Here are a couple scenarios:

  • You want the button to create a tag for this tiddler’s title AND some “set in stone” additonal tag, such as “example” or “meeting” (etc.)
  • You want the button to create a tag for this tiddler’s title AND for some dynamic value, such as whatever’s in this current tiddler’s “status” field, or whatever the current user’s user-name is (etc.)

Either way, you’ll modify this segment within the code above:

That string, as it appears, simply works with whatever the enclosing tiddler’s title is (the tiddler you’re working with in the story river), and assigns that value as the one tag the new tiddler will get.

You could add that tag plus “example” this way:

tags={{{ [<storyTiddler>] example +[format:titlelist[]join[ ]] }}}

You could add that tag plus “needs review” this way (note additional square brackets are needed whenever your desired tag name has a space within it):

tags={{{ [<storyTiddler>] [[needs review]] +[format:titlelist[]join[ ]] }}}

You could add that tag plus whatever’s in the status field of the enclosing tiddler (assuming that’s not itself a multi-word value) this way:

tags={{{ [<storyTiddler>] [{!!status}] +[format:titlelist[]join[ ]] }}}

Let me know if you have something else in mind, @msone

There is a problem with @Springer’s reply…

When the value of a widget parameter (e.g., tags) is set using “filtered transclusion”, only the FIRST item in the filter expression is used as the parameter value.

To properly construct a LIST of tags, you need to join all the filter values to create a single space-separated text string. In addition, any filter values that contain spaces need to be enclosed by doubled square brackets.

To do this, first list each of the individual tag values and THEN use +[format:titlelist[]join[ ]] to connect them all, like this:

tags={{{ [<storyTiddler>] example +[format:titlelist[]join[ ]] }}}
tags={{{ [<storyTiddler>] [[needs review]] +[format:titlelist[]join[ ]] }}}
tags={{{ [<storyTiddler>] [{!!status}] +[format:titlelist[]join[ ]] }}}

-e

2 Likes

Ah, that’s what I get for not testing the code!

Thanks, Eric! Fixing above…

Am I correct thinking by setting tags= it will replace any existing tags, so if you want to retain existing tags you need to include these in your filter as well, “add them back in”.

[Edited] I say this for completeness and future visitor who may be wishing to do something similar of existing tiddlers, not only on new tiddler (thus has no existing tags)

This specific discussion is about how to define the tags field contents when using tm-new-tiddler. Thus, there will never be “any existing tags” to “add back in”, and $action-listops is also not relevant, since there is no existing tags field to modify.

-e

Thank you very much for the suggestions. I’ll give it a try.

1 Like