A little transclude toy "code play"

114 views
Skip to first unread message

TonyM

unread,
Oct 25, 2019, 11:35:16 PM10/25/19
to TiddlyWiki
Folks,

I am just sharing a little code play here. I can imagine a number of possibilities with this. Hows your imagination?

Create a tiddler named $:/NS (for Name Service) and include the following
\define tiddlername() $:/NS/$(currentTiddler)$
<$list filter="[<tiddlername>has[text]]" variable=nul>
<$transclude tiddler=<<tiddlername>>/>
</
$list>
<$list filter="[<tiddlername>!has[text]]" variable=nul>
<$link to=<<tiddlername>> ><<currentTiddler>></$link>
</$list>

Now in any tiddler you can type
{{any name||$:/NS}}

  • If the tiddler does not exist, a link to a tiddler named "$:/NS/any name" is displayed, click to create it.
  • If the tiddler exists it will be transcluded, followed by an edit button to open it for edit.
How could you make use of this mechanism?

Regards
Tony

A Gloom

unread,
Oct 26, 2019, 12:11:26 AM10/26/19
to TiddlyWiki
$:/NS/

NS-- is that Namespace, does "$:/NS/" have a function or does it just create a NS subdirectory in the explorer? (haven't tried it yet-- busy with a demo on using the math macro with fields and in lists-- also a visual filter builder)

TonyM

unread,
Oct 26, 2019, 2:15:00 AM10/26/19
to TiddlyWiki
The $:/NS can be anything. Perhaps even $:/config temp or state. I used this because it was generic.

The idea is within this "namespace" your tiddler titles can be anything and not clash with regular tiddlers. For example $:/NS/pagebreak could contain the invisible code to throw a page break in print output. {{$:/NS/pagebreak}}

TonyM

unread,
Oct 26, 2019, 2:19:19 AM10/26/19
to TiddlyWiki
I accidentally posted. The example would be
{{pagebreak||$:/NS}}

REGARDS
Tony

@TiddlyTweeter

unread,
Oct 26, 2019, 1:42:33 PM10/26/19
to TiddlyWiki
Hi Tony

Unfortunately I don't get a clickable link.

Not clear what I am doing wrong.

TT

TonyM

unread,
Oct 26, 2019, 8:32:09 PM10/26/19
to TiddlyWiki
TT,

It works for me on tiddlywiki.com

The link is only clickable before the tiddler "$:/NA/any name" is created.

Once created it transcludes the content.

Here is a version that adds an edit button after the transcluded content.

\define tiddlername() $:/NS/$(currentTiddler)$
<$list filter="[<tiddlername>has[text]]">
<$transclude tiddler=<<currentTiddler>>/> {{||$:/core/ui/Buttons/edit}}

</$list>
<$list filter="[<tiddlername>!has[text]]" variable=nul>
<$link to=<<tiddlername>> ><<currentTiddler>></
$link>
</$list>


Regards
Tony

TonyM

unread,
Oct 26, 2019, 8:41:11 PM10/26/19
to TiddlyWiki
Post Script,

What I like about this method, is how $:/NS can contain code to activate various logic. I have separately created one that transcludes tagged items eg you call it with

{{tagname||$:/tags}} and $:/tags contains the logic to transclude all tiddlers tagged tagname.

In the one I am working on for custom actions for tiddler buttons I use

actions={{buttontiddler||$:/actiontags}} and it uses the current tiddler to manufacture a tag name eg $:/tags/$(currentTiddler)$ then transclude the content of tiddlers tagged $:/tags/$(currentTiddler)$ or $:/tags/buttontiddler

I can even see a transclusion that transcludes a hierarchy of tiddlers.

Regards
Tony

A Gloom

unread,
Oct 27, 2019, 12:03:29 AM10/27/19
to TiddlyWiki
The $:/NS can be anything. Perhaps even $:/config temp or state. I used this because it was generic.

The idea is within this "namespace" your tiddler titles can be anything and not clash with regular tiddlers. For example $:/NS/pagebreak could contain the invisible code to throw a page break in print output. {{$:/NS/pagebreak}}


Its not a placeholder just for this writeup (to be replaced by an actual value), but being uses as is (NS)

I recognize NS as a something form scripts (from working with scripts with svg which require establishing and accessing svg NS)

I know TW and its core macros operate off of built in script libraries

I just hadn't seen the term NS used outside of scripts, there's not a whole lot on namespace on the official wiki

Sycom

unread,
Oct 27, 2019, 7:30:47 AM10/27/19
to TiddlyWiki
Hello Tony,

I'm using something similar for my i18n macro.
https://groups.google.com/forum/m/#!topic/tiddlywikidev/a9rq0wsaGvs


* If a translation exists, it is displayed
* Else
* A message with link to the translation to be created is displayed
* If an original exists it is displayed
* else A message with link to the original tiddler to be created is displayed

In my case it's not $:/NS/ but $:/a_domain/i18n/lg-LG/ but the mechanism is the same.

Cheers

Sylvain
@sycom

Reply all
Reply to author
Forward
0 new messages