Hi again
Simply put, I would like to have a macro define that is the current tiddler’s title.
The macro call will insert it like this: {{$(tid)$ glossary}}
Could someone please give me a macro define that does this? Thanks!
Hi again
Simply put, I would like to have a macro define that is the current tiddler’s title.
The macro call will insert it like this: {{$(tid)$ glossary}}
Could someone please give me a macro define that does this? Thanks!
Hi Dave,
This code does what you’re asking:
\define myMacro() {{$(currentTiddler)$ glossary}}
Beware that this simple code wouldn’t work as-is in an editor toolbar button (yes, I saw your previous question ), because then $(currentTiddler)$
value would be the title of the button definition tiddler, not the edited tiddler.
For editor toolbar buttons, one should use $(targetTiddler)$
, but in this case the value would be “Draft of ‘New Tiddler’”:
\define myMacro() {{$(targetTiddler)$ glossary}}
Hope this will be helpful nevertheless.
Fred
Thanks Fred, for the snippet and the distinction! I am going to add this explanation to my documenting TW file.
Just in case:
<$action-sendmessage
$message="tm-edit-text-operation"
$param="wrap-selection"
prefix={{{ [[{{]] [<targetTiddler>get[draft.of]] +[join[]] }}}
suffix=""" glossary}}"""
/>
When placed in a tiddler tagged $:/tags/EditorToolbar
, this code wraps current text selection of the editor between {{ASDF
and glossary}}
if ASDF is the title of the currently edited tiddler.
To test it you can import this file in tiddlywiki.com:
myPlus.json (497 Bytes)
You’ll get a new editor toolbar button with a big “+” icon.
Fred
Hi Fred
This Editor Tool bar button blow does everything right except for one thing: the title of the new tiddler created has ‘draft of’. What do I do to fix that?
\define insertglossy(tid:"") $(targetTiddler)$ glossary
<$button class="tc-btn-invisible"><$action-sendmessage $message="tm-new-tiddler" title=<<insertglossy>> tags="" text="<div class='ltgraybk'>
''Glossary'' <$button class='tc-btn-invisible'><$action-sendmessage $message='tm-new-tiddler'
``` parent={{!!title}} />+</$button>
<$list filter='[search:parent:literal<currentTiddler>]'><span class='graybk'><$link/></span><br></$list>
</div>" />
Glossary h+
<$action-sendmessage
$message='tm-edit-text-operation'
$param='wrap-selection'
prefix={{{ [[{{]] [<targetTiddler>get[draft.of]] +[join[]] }}}
suffix=""" glossary}}"""
/></$button>
Hi Dave,
Replace all your code with this and you should be good to go:
Glossary h+
<$action-sendmessage
$message="tm-new-tiddler"
title={{{ [<targetTiddler>get[draft.of]] [[glossary]] +[join[ ]] }}}
tags=""
text="<div class='ltgraybk'>
''Glossary'' <$button class='tc-btn-invisible'><$action-sendmessage $message='tm-new-tiddler' parent={{{[<currentTiddler>get[draft.of]else<currentTiddler>]}}} />+</$button>
<$list filter='[search:parent:literal<currentTiddler>]'><span class='graybk'><$link/></span><br></$list>
</div>"
/>
<$action-sendmessage
$message='tm-edit-text-operation'
$param='wrap-selection'
prefix={{{ [[{{]] [<targetTiddler>get[draft.of]] +[join[]] }}}
suffix=""" glossary}}"""
/>
As an alternative, if the purpose of your edit button is not to wrap currently selected text but rather insert the transclusion at the caret position, you can use this:
Glossary h+
<$action-sendmessage
$message="tm-new-tiddler"
title={{{ [<targetTiddler>get[draft.of]] [[glossary]] +[join[ ]] }}}
tags=""
text="<div class='ltgraybk'>
''Glossary'' <$button class='tc-btn-invisible'><$action-sendmessage $message='tm-new-tiddler' parent={{{[<currentTiddler>get[draft.of]else<currentTiddler>]}}} />+</$button>
<$list filter='[search:parent:literal<currentTiddler>]'><span class='graybk'><$link/></span><br></$list>
</div>"
/>
<$action-sendmessage
$message='tm-edit-text-operation'
$param='insert-text'
text={{{ [[{{]] [<targetTiddler>get[draft.of]] [[ glossary}}]] +[join[]] }}}
/>
Edit: the macro definition and the button widget of your original code aren’t needed when using above code in an editor toolbar button definition.
Fred
Great project Dave, thanks for sharing!
In your demo wiki I noticed that the example tiddler Birds noteboxes
contains an outdated version of your code, maybe you should have a look
Fred
Thanks! Fixed that and cleaned up the noteboxes editor toolbar tiddler in two other places.
@DaveGifford another variable that is typicaly available when the currentTiddler has taken on new values is the storyTiddler, which is the tiddler in the story you are looking at, so it is often equivalent to currentTiddler and less likely to be changed.
@tw-FRed this is a great tip, the use of targetTiddler so I wanted to more fully understand the targetTiddler variable definition and scope and find there is no mention on tiddlywiki.com in the documentation.
Update: the system tiddler $:/core/ui/EditTemplate/body/editor sets targetTiddler from the currentTiddler thus making it available to all editor toolbar buttons.
Used to include non-button UI elements in the edit mode tiddler toolbar. For buttons see SystemTag: $:/tags/EditToolbar.
I also searched it today and I was surprised not to find mention of targetTiddler
in the Core Variables documentation. Maybe it’s not considered a core variable?
I discovered targetTiddler
variable existence while cloning the Bold
editor toolbar button for a personal project recently.
Fred
There is at least one place it should be documented in How to create dynamic editor toolbar buttons.
<<targetTiddler>>
variable inside the Editor Toolbar actions.
Observation;
Contributions are very welcome. – Including a remark here, I can guarantee that nothing will happen.
Same thing here. Contributions are very welcome.
The minimum that needs to happen is, that a GitHub issue is created. Otherwise the info here will be forgotten. (I will not create it)
I can make the change to the documentation, just wanted a hint of agreement, to go ahead.
Or are you thinking of something else?
If there is a PR, there can be discussion about the content. I think it would be good to include information about the “targetTiddler” in the toolbar button docs and it should be mentioned in the system tiddlers section too.
I will have to do this later in the day but when you refer to system tiddlers so you mean here https://tiddlywiki.com/#Naming%20of%20System%20Tiddlers or somewhere else? We mention $:/core/ui/EditorToolbar ?
I suggest to add 1 new system-tiddler per PR. Otherwise merging one info gets delayed if there is discussion about the other one.
I am not sure what system tiddler you are talking about, I was only doing documentation?