Automated list of custom (user-created) fields?

Another experiment. I just got the idea of adding a custom field for each topic when reading a book. Rather than using tags or links. I could add page numbers and other notes in the field input box.

Which means I would need a list of custom field id’s, each showing a list of links to the tiddlers that contain them. How might I do this?

Is this thread saying it is not currently possible?

[edit: Hey, I found it myself! Tucked away in $:/core/ui/EditTemplate/fields, the snippet is [!is[shadow]!is[system]fields[]search:title<newFieldName>sort[]] :except[[created]] :except[[creator]] :except[[draft.of]] :except[[draft.title]] :except[[modified]] :except[[modifier]] :except[[tags]] :except[[text]] :except[[title]] :except[[type]]

That is the list filter. But what would be the way to express the internal list of tiddlers that have each field listed in the outer list?

Expressed another way, what is the field id equivalent of [all[current]backlinks[]]?

Absolutely doable! Here’s a quick and dirty sample:

\function excludeFields()
[all[shadows]removeprefix[$:/language/Docs/Fields/]]
first-search-filter
second-search-filter
exclude-me
[prefix[ignore-]]
exclude-me-too
+[join[ ]]
\end

<table>
<tr>
	<th>Field</th>
	<th>Tiddlers</th>
</tr>
<$list filter="[!is[system]fields[]] -[enlist<excludeFields>] +[sort[]]" variable="field">
<tr>
	<td><<field>></td>
	<td><<list-links "[!is[system]has<field>]">></td>
</tr>
</$list>
</table>

Notes:

  • I’m using the function excludeFields to generate a list of fields you don’t want to see. The [all[shadows]removeprefix[$:/language/Docs/Fields/]] filter is a trick @Scott_Sauyet shared here; I think it’s more efficient than manually listing all the system fields you want to exclude. But below it, I’ve also included some examples of other fields you might want to remove — either by listing their titles directly (e.g. first-search-filter, exclude-me) or by writing a filter run to descibe them (e.g. [prefix[ignore]]). You can remove or alter any of these — just keep the final +[join[ ]], which is needed to reassemble all your field names into a space-separated list (for later use with enlist).
  • Within the table, I’m using $list to first generate one row per field name, and storing that field name in the variable <<field>>. Inside this outer list, I’ve nested a <<list-links>> to filter for tiddlers that use this field.
  • I used [!is[system]has<field>] as my list-links filter, which will display all the tiddlers that have a non-empty field. If you want to see all tiddlers that have the field name, empty or not, you can replace has with has:field.

Wow, thank you, Emily / @etardiff !

FYI the table looks much better when joined together like this

<table><tr><th>Field</th><th>Tiddlers</th></tr><$list filter="[!is[system]fields[]] -[enlist<excludeFields>] +[sort[]]" variable="field"><tr><td><<field>></td><td><<list-links "[!is[system]has<field>]">></td></tr></$list></table>

It’s fascinating how different all our brains are! :slightly_smiling_face: Personally, I find code very hard to parse when it’s all presented in a single line — even if it’s functionally identical.

I like this even more (same function above it)

<$list filter="[!is[system]fields[]] -[enlist<excludeFields>] +[sort[]]" variable="field"><details><summary><<field>></summary><span class="indent2"><$list filter="[!is[system]has<field>]"><$link/><br></$list></span></details></$list>

Now if only I could get it to work with a list-search…

Were you thinking of searching by field name? If so, you could try something like this:

\function excludeFields()
[all[shadows]removeprefix[$:/language/Docs/Fields/]]
first-search-filter
second-search-filter
exclude-me
exclude-me-too
+[join[ ]]
\end

\function tempSearch() $:/temp/search/ [<currentTiddler>] +[join[]]
\function searchTerm() [<tempSearch>get[text]]

<$edit-text tiddler=<<tempSearch>> tag=input placeholder="Search for a field" />

<$list filter="[!is[system]fields[]] -[enlist<excludeFields>] +[search:title<searchTerm>sort[]]" variable="field"><details><summary><<field>></summary><span class="indent2"><$list filter="[!is[system]has<field>]"><$link/><br></$list></span></details></$list>

I tied the text widget to a temporary tiddler so a) it won’t dirty your wiki, and b) it won’t persist across sessions. If you’d like a persistent state, you can replace $:/temp/ with $:/state/ in the tempSearch function.

1 Like

WOW! Thank you so much! I am going to have so much fun experimenting with this.

1 Like