Question: tm-download-file how to append a tiddler created on the fly to empty.html?

In https://tiddlywiki.com/, there is a Download Empty button, one can click and download a clean empty.html edition. It is here: https://tiddlywiki.com/prerelease/#Empty%20Edition

The button script is as below

<$button class="tc-btn-download">
<$action-sendmessage $message="tm-download-file" $param="$:/editions/tw5.com/download-empty" filename="empty.html"/>
Download Empty {{$:/core/images/save-button}}
</$button>

It uses a template ($:/editions/tw5.com/download-empty) to do the job!

Question: I need to create an extra tiddler and append it to the list of tiddlers in $:/editions/tw5.com/download-empty when click download empty!

  • that extra tiddler shall not be remined in the host wiki (here https://tiddlywiki.com), so it shall be created on the fly
  • the dirty button (save button on the sidebar) shall not be changed to red
    In other words, the extra tiddler shall be created in the process of downloading and appended to the empty.html

I suggest in $:/editions/tw5.com/snippets/download-empty-button add the action to create the tiddler before saving empty and deleting it after.

Almost anything triggers the dirty indicator however this will even happen once you delete the tiddler, see https://tiddlywiki.com/#SavingMechanism

You could add -[[$:/temp/test]] -[[$:/config/SaverFilter]] to $:/config/SaverFilter however by then you have already made other changes.

I suggest just delete your temp tiddler and go with the flow because a general reset dirty ignores the fact the user may have made other changes if only story and history. Although I can find some code or a bookmarklet to do it - but yes you need to make it available - another change.

As of TW 5.2.0 you can prepend a <script> tag to the HTML of a single file wiki to insert content into a wiki, I do this with my WebDAV farm work to create new wikis from templates but with the ability to add extra plugins to them.

Have a look at https://tiddlywiki.com/dev/#Data%20Storage%20in%20Single%20File%20TiddlyWiki to understand the structure of the script tag, and the core templates for saving a single file TW to understand the widgets used.

@Mohammad Busy week for me at the moment but if you get stuck, remind me after the weekend and I will post my wikitext code for you.

Hi Saq,
Much appreciated! I will give a try to see if I can manage things by learning from https://tiddlywiki.com/dev/#Data%20Storage%20in%20Single%20File%20TiddlyWiki

Thank you! Good wishes for you!
I will knock the door, if I get stuck :wink:

On further reflection, using a custom template for the empty file and a button that creates the new tiddler and then downloads the file might be an easier route.

1 Like

I am working on creating a proper template to export the core, selected plugins and if possible the tiddler created on the fly when I click the download empty.html!

Use case: In Gatha I create the plugin at the moment I click the export button, it is the exported tiddler not the one already created and then export! This is very similar to export button in Advanced Search > Filter.

I am trying to see how I can append this plugin tiddler to the custom empty.html (I call it demo.html)

Hi @saqimtiaz
Investigating the $:/editions/tw5.com/snippets/download-empty-button indicates I have to create a custom $:/core/templates/tiddlywiki5.html
Am I on the right track?

To remind what was the main request, I summarize it: I am exporting an empty.html from my working Tiddlywiki and need to append a set of tiddlers as a plugin to it! So, I have to create the plugin on the fly! I cannot create the plugin and append and delete it!

This is where it stores the ordinary tiddlers, and I assume a plugin is an ordinary tiddler, so I need to edit somewhere here

<!--~~ Ordinary tiddlers ~~-->
`{{$:/core/templates/store.area.template.html}}`

In $:/core/templates/store.area.template.html, I see there is a script deal with storing tiddlers.

Mohammad

Another way may be to use the innerwiki plugin. You can use the data statements to include your plugin in the resulting wiki. In that wiki you can click save and commit empty plus plugin to disk.

But does this give you the result you want?

If not could you explain why not?

The tm-download message only accepts a tiddler template to render and not raw text, so yes you will need a custom template.

I recommend to add something like this to the beginning of a copy of $:/core/templates/tiddlywiki5.html:

`<script class="tiddlywiki-tiddler-store" type="application/json">[`
	<$vars newline={{{ [charcode[10]] }}}>
		<$text text=<<newline>>/>
		<$list filter="[[$:/config/sq/fs/new-wiki/plugins]indexes[]] :filter[[$:/config/sq/fs/new-wiki/plugins]getindex<currentTiddler>match[yes]]" counter="counter" template="$:/core/templates/html-json-tiddler"/>
		<$text text=<<newline>>/>
	</$vars>
`]</script>`

Customize the list filter to add the tiddlers that you want. In your case you will need to also use your own template instead of $:/core/templates/html-json-tiddler that creates the tiddler JSON from variables that you have defined in the template. If you are only adding a single tiddler that you do not need the $list widget.

Note that you need need to escape < character to \u003c if it exists in any of the fields of your tiddler.

1 Like

Thank you Saq,
I go with your recommendation and update you with result! I think, now I should be able to write the solution :wink:

@TW_Tones, I cannot use another plugin for this. I have to write the simplest solution as this will be part of Gatha.

2 Likes

Here is a simple example of a custom template that creates an empty with an extra tiddler Foo:

\define saveTiddlerFilter()
[[$:/core]] [[$:/isEncrypted]] [[$:/themes/tiddlywiki/snowwhite]] [[$:/themes/tiddlywiki/vanilla]] -[[$:/boot/boot.css]] -[type[application/javascript]library[yes]] -[[$:/boot/boot.js]] -[[$:/boot/bootprefix.js]] +[sort[title]]
\end
\define savingEmpty()
yes
\end

<$let
	title={{{ [[Foo]] }}}
	text=""
	tags=""
	modified="20220212133835026"
	created="20220212133835026"
>
`<script class="tiddlywiki-tiddler-store" type="application/json">[`
`{"created":"`<<created>>`","text":"`<$text text=<<text>>/>`","tags":"","title":"`<$text text=<<title>>/>`","modified":"20220212133835026"}`
`]</script>`
</$let>
{{$:/core/templates/tiddlywiki5.html}}

Note:

  1. Escape < characters in any of the fields
  2. To add multiple tiddlers, you will need to use a $list widget and the counter variable to insert commas between the tiddler objects, see the example in the core template or my example above.
  3. You could also create temp tiddlers in the original wiki with different titles and the real title saved in a different field. Then in the template, use a list widget to get the temp tiddlers and create the JSON with them with the proper title for each widget. This way the only tiddlers created in the original wiki are temp tiddlers that will not be saved.
2 Likes

Is this the solution: escapeUnsafeScriptChars="yes" when I use $jsontiddler widget?

You cannot use the jsontiddler widget since you do not want to create the tiddler in the original wiki. That is why I gave you an example of creating a tiddler from variables. Perhaps try the search-replace operator.

1 Like

Yes, that’s true! in case of exporting plugin as json file, I use this widget and it creates the json on the fly!
But here I have to append it in empty.html!

Thank you

1 Like