Field or text reference in template

133 views
Skip to first unread message

TonyM

unread,
Oct 19, 2019, 9:40:53 PM10/19/19
to TiddlyWiki
Folks

I am exploring the power of templates in tiddlywiki. Please consider this

{{||template}}
{{tiddlername||template}}

In the tiddler "template" the value of current Tiddler will be that of the currenttiddler in the first example and tiddlername in the second example.

However in the following cases


{{!!fieldname||template}}
{{tiddlername!!fieldname||template}}

Is there a way in the template tiddler for me to get the name of the fieldname?

Thanks in advance
Tony

PMario

unread,
Oct 21, 2019, 5:31:50 AM10/21/19
to TiddlyWiki
On Sunday, October 20, 2019 at 3:40:53 AM UTC+2, TonyM wrote:

{{!!fieldname||template}}

{{tiddlername!!fieldname||template}}

Is there a way in the template tiddler for me to get the name of the fieldname?


<$set name="myCurrentField" value="fieldname">
{{!!fieldname||template}}
</$set>

<$vars myCurrentField="fieldname">
{{!!fieldname||template}}
</$vars>

should do it. The same mechanism is used within TW templates. currentTiddler is "just a variable" defined with set- or vars-widget.

You should use a my-prefix or something similar. currentField may clash with a future core.

-m

TonyM

unread,
Oct 21, 2019, 7:58:19 AM10/21/19
to TiddlyWiki
Mario

thanks for the feedback. I am actually working on the button actions hackability we have discussed elsewhere. There seems a Great way to combine both our ideas.

With your answer above Does that mean I must know the fieldname and set it to a variable, so that I can access the variable inside the template?

I was wondering if template was transcluded by a random transclusion e.g. {{name!!field||template}} if we can extract the "field". Or will it only transclude name!!field?

I ask because if I used {{name||template}}, inside the template the currentTiddler=name, so I can get the name, I am wondering about getting the "field".

Regards
Tony

Mark S.

unread,
Oct 21, 2019, 11:48:46 AM10/21/19
to TiddlyWiki
Hi Tony,

I think you would have to hack the parser if you wanted the field and tiddler name to be available.

But you can fake it now, if you're willing to forego !!

Make a tiddler called "test" (must be called test or recursion error will occur). Paste in:

<$list filter="[<currentTiddler>] -[[test]] -[[Draft of 'test']]">
<$set name=mytid filter="[
<currentTiddler>split[--]]" select=0 >
<$set name=myfield filter="[
<currentTiddler>split[--]]" select=1 >
<$tiddler tiddler=<
<mytid>>>
<$set name=test field=<
<myfield>> tiddler=<<mytid>> >
I see <
<test>>.
</$set>
</$tiddler>
</$set>
</$set>
</$list>

Now you can use syntax like {{mytiddler--myfield||test}}

-- was used because !! is already grabbed by the parser.

Of course, at this point you might as well use a macro.

TonyM

unread,
Oct 21, 2019, 7:54:16 PM10/21/19
to TiddlyWiki
Mark/Mario,

Thanks for your demonstration of a method to pass a field/string into the template with the use of a delimiter. I like it, but perhaps not to use in this case. The reason? I wanted to know if there were an intrinsic way to do it, I could have used the fact to simplify what I was working on, so your method achieves the the detail but not the spirit. I realise now I should have added to my first post I was wondering if there were a simple way to do this.

In fact in someways I am trying to subvert the mechanism.

I did discover the Transclusion Variable `<<transclusion>> ` 

Which promises a possible method by parsing it in the transcluded tiddler

For those interested in hacking

I am looking at getting tricky here, if in a button I specify actions={{tiddlername||tiddlertemplate}} then in tiddlertemplate I am automatically constructing a tag name of $:/tags/tiddlername I can then transclude all tiddlers tagged with $:/tags/tiddlername. 

So if I wanted custom actions assigned to the close button I can add to the $:/core/ui/Buttons/close 
actions={{$:/core/ui/Buttons/close||$:/tags}}

  • This works, I am quite happy with it
  • I have added the tiddler $:/tags and this handles the "request" with wikitext/macros (ie its the template)
  • The actions transcluded are the tiddlers tagged $:/tags/$:/core/ui/Buttons/close
  • Note: I need to provide the tiddler name $:/core/ui/Buttons/close because it is different to the current tiddler in buttons

The original question in this thread "Field or text reference in template"
was to see if I could improve this to make the solution even more generic, perhaps using field name as a parameter to handle via transclusions;
  • Actions/transclude code
  • Transclude content
  • List tiddler titles
  • Provide key=value pairs and more
Mario

in regards to you approach

It is already possible to use {{anyname||templatename}} and make use of anyname in the logic within the template. This can in effect be a virtual tiddler title. However in this use case I must have access to the code tiddler title $:/core/ui/Buttons/close so I can determine the tagged tiddlers and transclude them. This I am forced to use the anyname to pass the button tiddler.

I am trying to avoid additional code in the button tiddler but I could set codeTiddler=$:/core/ui/Buttons/close and transclude with {{||$:/tags}} as you suggest, even {{parameter||$:/tags}} I think however perhaps
\define codeTiddler() $:/core/ui/Buttons/close
would be better?

The reason I was asking about the field  was to see of I could do something like this {{$:/core/ui/Buttons/close!!parameter||$:/tags}} where parameter can be interrogated in the template.

Regards
Tony

Mark S.

unread,
Oct 21, 2019, 11:39:06 PM10/21/19
to TiddlyWiki

Does this syntax actually work? It appears to me that TW always strips away the field name part. Or is there a step I'm missing?

TonyM

unread,
Oct 22, 2019, 12:23:41 AM10/22/19
to TiddlyWiki
Mark

That is correct. The following work of course

{{tiddlername!!fieldname}}

{{tiddlername}}

{{||template}}

{{tiddlername||template}}

The format of the transclusion is more detailed than that. I am just not sure if the documentation covers this adequately.

I may try and find where the {{||template}} is handled in the core.

Thanks
Tony

Reply all
Reply to author
Forward
0 new messages