Transclusion into variable or something similar?

155 views
Skip to first unread message

Stephan Hradek

unread,
Jul 1, 2019, 7:27:15 AM7/1/19
to tiddl...@googlegroups.com
Hi!

After quite some time I'm back to using TiddlyWiki (hopefully) a bit more regularly.

Seems my kowledge has rusted over the last 2 years. I cannot figure out how to get solved what I want to achieve.

The idea is the following: I have to create some customer information and in that process I have to send mails.

So while I document what I do I also want to enter the customer's data into my TW. The idea I have is that TW will already prepare the mail for me.

This works but I have to copy & paste the mail. Much easier would be to click on a prepared mailto-link which will invoke my mail program, prefilled with all the data.


Here is an example as to how far I came:

Tiddler "data"

name:recipient
text:the text to send

Tiddler "MailText"

Hi <<the_recipient>>!

Thisisyour text<<the_text>>.

Regards

Tiddler PreparedMail

<$set name="the_recipient" tiddler="data" index="name">
<$set name="the_text"      tiddler="data" index="text">

<pre>
{{MailText}}
</pre>


</$set>
</$set>

In order to be able to create a mailto-link, I will have to apply encodeuri to the mailtex. So $list is requiredt:

<$set name="the_recipient" tiddler="data" index="name">
<$set name="the_text"      tiddler="data" index="text">


<$list filter="[[MailText]get[text]encodeuri[]]">

<<currentTiddler>>

</$list>


</$set>
</$set>

Unfortunately encodeuri does not receive the "Transclusionresult" but the plain MailText and so the output of the las example will be:

Hi%20%3C%3Cthe_recipient%3E%3E!%0A%0AThis%20is%20your%20text:%20%3C%3Cthe_text%3E%3E.%0A%0ARegards

And not the required

Hi%20recipien!%0A%0AThis%20is%20your%20text:%20the%20text%20to%20send.%0A%0ARegards

Is there any way I can solve this? Can I, for exampl, get the fully transcluded text into a variable so that I can create a mailto-link?

Many tia…

PMario

unread,
Jul 1, 2019, 7:44:40 AM7/1/19
to TiddlyWiki
Hi,
May be the view-widget can help?
-m

Mat

unread,
Jul 1, 2019, 8:06:36 AM7/1/19
to TiddlyWiki
Hey there's a familiar name! Welcome back Stephan.

I think you need to wikify the MailText (wikifywidget) before sending to encodeuri

<:-)

Mohammad

unread,
Jul 1, 2019, 8:31:50 AM7/1/19
to TiddlyWiki
Welcome back Stephan!
Hope to see your great work and contribution again here in TW forum!

Cheers
Mohammad

Stephan Hradek

unread,
Jul 1, 2019, 12:22:36 PM7/1/19
to TiddlyWiki


Am Montag, 1. Juli 2019 14:06:36 UTC+2 schrieb Mat:
Hey there's a familiar name! Welcome back Stephan.

Thanks! Also to @PMario and @Mohannad
 
I think you need to wikify the MailText (wikifywidget) before sending to encodeuri

That seems like the solution. Thanks a lot! 

TonyM

unread,
Jul 1, 2019, 7:16:52 PM7/1/19
to TiddlyWiki
Stephen,

Welcome back, if you can share your ultimate result that would be great. I have tried something similar a number of times but have found it very fragile. My suspicion is the best way maybe to have a template tiddler not unlike all the savers and exporters use that defines the mailto link with the content from the current tiddler. I hoped to have any tiddler with an email address have a send mail button that allowed it to automatically compose the email and open the default mail program. Ideally there would be a mechanism to "attach" other tiddlers as files, such as a json tiddler or image.

I am prepared to put sometime into collaboration on this because I also need this for a client solution.

Regards
Tony

A Gloom

unread,
Jul 1, 2019, 8:43:43 PM7/1/19
to TiddlyWiki
Stephan,

Welcome back.  I have no answers but I will definitely be interested in what you figure out.

Stephan Hradek

unread,
Jul 3, 2019, 2:24:38 AM7/3/19
to TiddlyWiki
Hi Tony


Am Dienstag, 2. Juli 2019 01:16:52 UTC+2 schrieb TonyM:
Stephen,

Welcome back, if you can share your ultimate result that would be great.

I will. I already have something working and wil describe it, as soon as I have time :/ extensively. But here is what I do just roughly sketched out.

1. Create one or more Mailtemplate Tiddlers. Each tiddler has to have:
   1. The Mail text in the text-field
   2. a subject-field
   3. a recipients-field
   Each field may contain <<VARIBALE>>s to fill in. So you can, if you want, provide recipients or (part of) the subject and text by setting a variable.
2. have the mailto-tiddler (see below)
3, use the mailto tiddler like this
<$set … define your variables>
{{Mailtemplate Tiddler -- Linktext||mailto}}
</$set>
and you will get a link called "Linktext" which should open a pre-filled Mail ready to be sent.

Full example

Tiddler "Mailtemplate Customer ready"
Hi Team.
 
Please be informed that I've created.  Customer <<Customername>>.
 
Best Regards,

field "subject": "Cusomer <<Customername>> created
field "recipients": "te...@compa.ny"
I prefer to set the tiddler's type to text/plain to be able to see all variables


Tiddler using it
Customername: <$edit tiddler="Customerdata" index="name"/>
<$set name="Customername" tiddler="Customerdata" index="name">
{{Mailtemplate Customer ready -- Inform the team||mailto}}
</$set>
Note: The example will create a dictionary tiddler "Customerdata".


Tiddler: "mailto"
\define mailto()
<a href="mailto:$(recipients_encoded)$?subject=$(subject_encoded)$&body=$(body_encoded)$">$(linktext)$</a>
\end

<!-- separator used between tiddler and linktext -->
<$set value=" -- "
  name="sep">

<!-- extract the tiddler's title-->
<$set select="0" filter="[all[current]splitbefore<sep>removesuffix<sep>]"
 name="tiddler">

<!-- extract the linktext -->
<$set select="0"  filter="[all[current]removeprefix<tiddler>removeprefix<sep>]"
  name="linktext">

<!-- get the mail template's text -->
<$set tiddler=<<tiddler>> field="text"
  name="body">

<!-- get the subject from the subject field -->
<$set tiddler=<<tiddler>> field="subject"
  name="subject">

<!-- get the recipients from the recipients field -->
<$set tiddler=<<tiddler>> field="recipients"
  name="recipients">

<!-- wikify the text to resolve all used variables -->
<$wikify text=<<body>>
  name="body_text">

<!-- wikify the subject to resolve all used variables -->
<$wikify text=<<subject>>
  name="subject_text">

<!-- wikify the recipients to resolve all used variables -->
<$wikify text=<<recipients>>
  name="recipients_text">

<!-- encode the text -->
<$set select="0" filter="[<body_text>encodeuri[]]"
  name="body_encoded">

<!-- encode the subject -->
<$set select="0" filter="[<subject_text>encodeuri[]]"
  name="subject_encoded">

<!-- encode the recipients -->
<$set select="0" filter="[<recipients_text>encodeuri[]]"
  name="recipients_encoded">

<!-- create the link -->
<<mailto>>

</$set>

</$set>

</$set>

</$wikify>

</$wikify>

</$wikify>

</$set>

</$set>

</$set>

</$set>

</$set>

</$set>


I'm still working on it, but maybe this is already useful to you.

TonyM

unread,
Jul 3, 2019, 7:29:53 AM7/3/19
to TiddlyWiki
Thaks for sharing

I will have play with this. I have tried similar things but always find using mailto fragile, it seems to break at a whim.

I expect as a result my dreams of adding attachments or using rich html emails is but a pipe dream.

Regards
Tony

Stephan Hradek

unread,
Jul 3, 2019, 2:18:37 PM7/3/19
to TiddlyWiki
Attachments won‘t work. You could only provide a link to a web location where you keep the file for the user see https://stackoverflow.com/questions/5233556/using-mailto-to-send-email-with-an-attachment

HTML mails also don‘t work https://stackoverflow.com/questions/5620324/mailto-link-with-html-body

Reply all
Reply to author
Forward
0 new messages