Share Tiddlers JSON Bundle

I want to be able to import a JSON bundle of Tiddlers to share with others, but whenever I try to import, it automatically imports the tiddlers, rather than the JSON file. I get why, but is there a workaround for when I just want to share a Tiddler bundle in my public wiki? Thank you.

The import process is what is trying to parse it into tiddlers. The simple workaround is create a tiddler and paste the json content into it.

One can make a custom $browse widget to import a json without triggering the $:/import process.

You can also interupt the import process and rename $:/import as it is a json file. remove the fields created in that tiddler.

let me know if you want more details :cowboy_hat_face:

1 Like

I would like to know more, thank you.

Give this a try:

Edit the $:/core/ui/ViewTemplate/body/import shadow tiddler:

At the end of the buttons() macro definition, add this line (after the </$select>)

<<saveAs plugin>> <<saveAs bundle>>

Then, add a new separate \procedure definition (outside the buttons() macro):

\procedure saveAs(type)
\procedure create()
	<$tiddler tiddler={{{ [<popid>get[name]else<name>] }}}>
	<$action-setfield text={{$:/Import}} type="application/json"/>
	<%if [<type>match[plugin]] %><$action-setfield plugin-type=plugin/><%endif%>
	<$action-navigate/>
	</$tiddler>
\end create
<$let popid={{{ [[$:/state/popup/Import/SaveAs/]] [<type>] [<qualify>] +[join[]] }}}
	   name={{{ [<type>match[plugin]then[$:/plugins/MyPlugins/newplugin]else[MyBundle]] }}}>
<$button popup=<<popid>>>Save as <<type>></$button>
<$reveal state=<<popid>> type=popup class=tc-block-dropdown style="padding:0.5em;">
	@@float:right;<$button>cancel</$button> <$button actions=<<create>>>create</$button>@@
	<<type>> name:
	<div style="clear:both;">
	<$edit-text class=tc-popup-handle tiddler=<<popid>> field=name default=<<name>> size=30/>
	</div>
</$reveal>
\end

Notes:

  • The first change adds two new buttons (“Save as plugin” and “Save as bundle”) in the $:/Import interface. When clicked, these buttons invoke the saveAs() procedure, passing either “plugin” or “bundle” as the type parameter.
  • The new saveAs(type) procedure does the following:
    • Display a $button with either “Save as plugin” or “Save as bundle” label
    • When this button is clicked, display a popup with a text input for entering either a new plugin tiddler title (default="$:/plugins/MyPlugins/newplugin") or a new bundle tiddler title (default="MyBundle")
    • Pressing “cancel” just dismisses the popup without doing anything else
    • Pressing “create” invokes the create() procedure (locally-defined inside the saveAs() procedure), which:
      • Gets the new tiddler title from the text input field (or uses the default value is nothing was entered)
      • Copies the $:/Import tiddler’s text contents to the new tiddler and sets type="application/json"
      • If type is “plugin”, it also sets plugin-type="plugin"
      • It then automatically navigates to the newly created tiddler so you can see the results.

Note that, if you created a new plugin, its contents are immediately available as shadow tiddlers in your TiddlyWiki.

To share the plugin with others, they just need to drag-and-drop the plugin tiddler into their TiddlyWiki. When they press the “import” button in the $:/mport tiddler, the plugin is installed and all the shadow tiddlers are then available to them.

Sharing a “bundle” is a little bit more involved. First, drag-and-drop the bundle into another TiddlyWiki and import it. Next, to “unpack” it’s contents, edit the newly imported bundle tiddler and add a plugin-type field with a value of “import”. As soon as the change to the bundle tiddler is saved, it will display the TWCore import interface instead of the JSON contents. They can then press the “import” button to unpack the bundle.

enjoy,
-e

4 Likes

Thank you! Now how do I link to the resulting Tiddler bundle (a bundle of icons I made) in a way so that others can install it by dragging & dropping the link on their wiki?

Also, if I export the bundle tiddler as json & then import it, it imports it as json rather than a bundle of tiddlers, so if someone wanted to download the bundle and import it later, it wouldn’t work. What am I doing wrong?

Hi Gloria, I just wanted to offer an alternate approach to your question…

By default, if you drag a tag-pill from one wiki and drop it into another, it will open an import dialogue containing all the tagged tiddlers. So if you want people to be able to import a bunch of “loose” unpackaged tiddlers from your wiki, I think the absolutely easiest way is to give them all the same tag, then point people to the tag pill.

You can even add a tag-pill in the text of any tiddler — try adding <<tag "HelloThere">> to a new tiddler on TW-com.

If you use the “save as plugin” button, it will create a plugin tiddler whose contents can be imported just by dragging the plugin tiddler’s title to another TiddlyWiki. All you need to do is to put a link to the plugin tiddler somewhere in your content (e.g., [[My Favorite Icons|PluginTiddlerTitle]]). The user then needs to

  1. drag-and-drop the “My Favorite Icons” link into their TiddlyWiki
  2. press the “import” button in “$:/Import” to install the plugin

However, as I explained in my previous post, if you use the “save as bundle” button, while you still need to provide a link (e.g., [[My Favorite Icons|BundleTiddlerTitle]], there’s a few extra steps to “unpack” the bundle after importing it into another TiddlyWiki. Specifically, the user needs to

  1. drag-and-drop the “My Favorite Icons” link into their TiddlyWiki
  2. press the “import” button in “$:/Import” to install the “My Favorite Icons” bundle
  3. view the imported “My Favorite Icons” tiddler (which shows JSON data)
  4. edit the “My Favorite Icons” tiddler to add a plugin-type field with a value of import
  5. press “done”
  6. press the “import” button in “My Favorite Icons” (which now shows a TWCore import interface) to “unpack” the bundle

To reduce those extra steps, I’ve just updated my code for creating bundles so that the necessary plugin-type=import field is automatically set as soon as the bundle is created. The result is that the created bundle no longer shows JSON data… instead, it looks like a TWCore import tiddler.

This eliminates steps 4 and 5 above, so the new sequence is:

  1. drag-and-drop the “My Favorite Icons” link into their TiddlyWiki
  2. press the “import” button in “$:/Import” to install the “My Favorite Icons” bundle
  3. view the imported “My Favorite Icons” tiddler
  4. press the “import” button in “My Favorite Icons” to “unpack” the bundle

To make it easier to set this up, you can get a copy of my modified import code directly from TiddlyTools $:/core/ui/ViewTemplate/body/import

enjoy,
-e

1 Like

Addendum: since the “save as plugin” method seems to be much simpler, why would you ever use the “save as bundle” method? Here are some differences between the two methods…

Save as plugin:

  • With “save as plugin”, the plugin tiddler exists in your TiddlyWiki as a regular tiddler, and the “payload” tiddlers exist as “live” shadows in your TiddlyWiki.
  • When the plugin tiddler is then imported to another TiddlyWiki, the plugin tiddler itself is retained as a regular tiddler and the payload tiddlers are installed as “live” shadows in the new TiddlyWiki.
  • The plugin tiddler must be retained in the new TiddlyWiki so that it can be automatically “unpacked” each time that TiddlyWiki is reloaded (assuming, of course, that you saved the new TiddlyWiki before reloading).

Save as bundle:

  • With “save as bundle”, the bundle tiddler exists in your TiddlyWiki as a regular tiddler, but the payload tiddlers are simply stored as JSON within that one bundle tiddler and are not available as “live” shadows so they will have no effect on your TiddlyWiki.
  • When the bundle tiddler is then imported to another TiddlyWiki, the bundle tiddler itself exists in the new TiddlyWiki as a regular tiddler, and the payload tiddlers also exist regular tiddlers (not shadows) in the new TiddlyWiki.
  • However, after unpacking the bundle tiddler, it is automatically overwritten with an “import successful” status report. This overwritten bundle tiddler can be safely discarded and the new TiddlyWiki will still retain the unpacked payload tiddlers when it is reloaded (assuming, of course, that you saved the new TiddlyWiki before reloading)

Note that, in my opinion, neither method is “better” than the other. It all depends upon what results you want or need.

-e

1 Like

Thank you! Now how do I link to the resulting Tiddler bundle (a bundle of icons I made) in a way so that others can install it by dragging & dropping the link on their wiki?

What you are describing reminds me a lot of one of my macros. Maybe this could interest you:

\define export-btn()
<$button tooltip="Click to download or drag and drop to install" class="tc-btn-invisible" dragFilter=<<__filter__>> >
<$action-sendmessage $message="tm-download-file" $param="$:/core/templates/exporters/JsonFile" exportFilter=<<__filter__>> filename={{{ [<__filename__>] .json +[join[]] }}} />
{{$:/core/images/export-button}}
</$button>
\end

\define export(filter , filename:"demo" , hint:"Click this button to download a json file containing all relevant tiddlers, or drag and drop to install directly into your tiddlywiki : ")
<$list filter="[<storyTiddler>is[current]]" emptyMessage=<<export-btn>>>
$hint$<<export-btn>>
</$list>
\end

For example, to make a button that export all the icons, you would do this:

<<export filter:"[all[shadows+tiddlers]tag[$:/tags/Image]]" filename:"Tiddlywiki Icons" hint:"Click this button to download a json file containing all relevant tiddlers, or drag and drop to install directly into your tiddlywiki : ">>

Demo: Demos — Q&A and tools for tiddlywiki

1 Like