List of Fields in a Template Tiddler

98 views
Skip to first unread message

stevesuny

unread,
Mar 10, 2017, 4:28:04 PM3/10/17
to TiddlyWiki
I'm picking up this thread from May 2016.

I'm interested in listing the fields in a tiddler, using a template. Here is the code of my current template, which has two methods of accomplishing this task. Both work (!)

My question: How can I get Method One to place a line break after teach name/value pair? Seems that would be more efficient and more elegant than method Two, which works well enough, but requires six lines rather than one line of code. I've just discovered the $fields command, and am exploring uses for it. Thanks! //steve.

<$list filter="[is[current]tag[wish]]">
<h1>One</h1>
<$fields template='$name$: $value$'/>

<h2>Two</h2>
<$wikify name=tid text={{!!title}}>
<$list filter="[
<tid>fields[]] -[[text]]" variable="fieldname">
<$text text=<
<fieldname>>/>:
<$view tiddler=<
<tid>> field=<<fieldname>>/><br>
</$list>
</$wikify>


</$list>




<hr>
^^[[wish template]]^^
</$list>


Th:

Eric Shulman

unread,
Mar 10, 2017, 4:46:20 PM3/10/17
to TiddlyWiki
On Friday, March 10, 2017 at 1:28:04 PM UTC-8, stevesuny wrote:
My question: How can I get Method One to place a line break after teach name/value pair? Seems that would be more efficient and more elegant than method Two, which works well enough, but requires six lines rather than one line of code. I've just discovered the $fields command, and am exploring uses for it. Thanks! //steve.

<$list filter="[is[current]tag[wish]]">
<h1>One</h1>
<$fields template='$name$: $value$'/>

<h2>Two</h2>
<$wikify name=tid text={{!!title}}>
<$list filter="[
<tid>fields[]] -[[text]]" variable="fieldname">
<$text text=<
<fieldname>>/>:
<$view tiddler=<
<tid>> field=<<fieldname>>/><br>
</$list>
</$wikify>


</$list>

The documentation for <$fields> says that it is used *internally* by the TW core (in particular, the FileSavingMechanism).  The 'template' param only accepts plain text and two special variable references ($name$ and $value$).  It has very limited ability control the output format.  Using <$list> allows you to provide whatever output formatting you like.

Also, you don't need to use <$wikify> to get the current tiddler's title, and you don't need to provide the tiddler="..." param to <$text> and <$view> because the <<currentTiddler>> is used by default.  You can reduce the code to just 3 lines:
<$list filter="[<currentTiddler>fields[]] -[[text]]" variable="fieldname">
   <$text text=<
<fieldname>>/>: <$view field=<<fieldname>>/><br>
</$list>

enjoy,
-e
Eric Shulman
TiddlyTools: Small Tools for Big Ideas! (tm)
InsideTiddlyWiki: The Missing Manuals

stevesuny

unread,
Mar 10, 2017, 10:45:57 PM3/10/17
to TiddlyWiki
Thanks Eric, that's great.

So with this approach, we can willy-nilly loop through field values for listed tiddlers. Very nice!
Reply all
Reply to author
Forward
0 new messages