This is very similar to saving a .tid file, but also a bit tricky.
We can use the same template, as used to save the .tid file. So we need
-
exportFilter β¦ [<tv-history-list>get[current-tiddler]]
-
we need to build a mailto: link
-
[ext[links]] are converted to <a href="...
so we will create HTML code here, since it is easier than to create wikitext that needs to be rendered.
-
We can use some functions to define the different elements and then concatenate everything together.
-
\define mailto() mailto:name@example.com
β¦ defines the base address. name
needs to be defined as needed
-
\function f.user() [{$:/status/UserName}]
β¦ returns the name from the ControlPanel setting
-
\function f.currentTiddler() [<tv-history-list>get[current-tiddler]]
β¦ reads the HistoryList current-tiddler
-
\function f.subject() "?subject=Tiddler: " [<f.currentTiddler>] " - " [<f.user>] +[join[]]
β¦ builds the mailto: subject prefix, gets current-tiddler, adds " - ", adds user-name and concatenates it to a string
-
\function f.body() "&body=" [<body-text>encodeuri[]] +[join[]]
β¦ defines the body-prefix, reads the body-text variable and uri-encodes it, so it can be used in a link
-
\function f.createMailto() [<mailto>] [<f.subject>] [<f.body>] +[join[]]
β¦ joins all functions from above together
Then we need some code that uses those functions.
<$wikify name="body-text" text="""
<pre><code>
{{||$:/core/templates/exporters/TidFile}}
</code></pre>
""">
<a class="custom-send-mail"
href=`${ [<f.createMailto>] }$` >{{$:/core/images/mail}}
</a>
</$wikify>
- wikify text= β¦ uses the template that creates the tiddler text
-
<pre><code>
β¦ converts it to plain text
- the A HTML element uses
href=`${ [<f.createMailto>] }$`
β¦ to concatenate all the functions from above
- Some styling is needed to create the right size and positioning of the icon in the sidebar
The full code looks like this
title: $:/_custom/ui/Buttons/save-current-tiddler
tags: $:/tags/PageControls
caption: {{$:/core/images/mail}} Mail current-tiddler
description: Mail HistoryList!!current-tiddler
\whitespace trim
\define exportFilter() [<tv-history-list>get[current-tiddler]]
\define mailto() mailto:name@example.com
\function f.user() [{$:/status/UserName}]
\function f.currentTiddler() [<tv-history-list>get[current-tiddler]]
\function f.subject() "?subject=Tiddler: " [<f.currentTiddler>] " - " [<f.user>] +[join[]]
\function f.body() "&body=" [<body-text>encodeuri[]] +[join[]]
\function f.createMailto() [<mailto>] [<f.subject>] [<f.body>] +[join[]]
<style>
.custom-send-mail svg {
width: 1em;
height: 1em;
}
.custom-send-mail {
display: inline-block;
vertical-align: bottom;
}
</style>
<$wikify name="body-text" text="""
<pre><code>
{{||$:/core/templates/exporters/TidFile}}
</code></pre>
""">
<a class="custom-send-mail"
href=`${ [<f.createMailto>] }$` >{{$:/core/images/mail}}
</a>
</$wikify>
$___custom_ui_Buttons_mail-current-tiddler.json (1.2 KB)
have fun!
mario