Selective Linkifying of Field Values

One of the side projects I’ve been working on off and on is a quick and easy way to create dossiers for my story’s characters, i.e. like a wiki page for the character like what you would see if you went to a website like Fandom.

I had the initial design and layout done, but one of the things that I never figured out, was listing fields that contain double square brackets and showing them as links, while leaving the rest as plaintext.

For instance, if I have a tiddler titled “Johnny J. Doe” and the text field contains:

\define systemFields() draft.title draft.of title tags text created creator modified modifier

<table class="tc-max-width">
	<tbody>
		<$list filter="[all[current]fields:exclude<systemFields>sort[]]" variable="selectedFields">
			<tr>
				<th> <$text text={{{ [<selectedFields>] }}}/> </th>
				<td> {{{ [all[current]get<selectedFields>] }}} </td>
			</tr>
		</$list>
	</tbody>
</table>

with the fields:

birth-date: 04/04/2004
birth-parents: [[Samual Doe]] [[Madison Doe]]
birth-place: [[Nowhere, Colorado, USA]]
birth-name: [[Johnathan James Doe|Johnny J. Doe]]
expiration-date: 04/04/2084
expiration-place: [[Home, Pennsylvania, USA]]

How can I set it so that the text itself shows as plaintext, but if it is wrapped in double square brackets, it renders as links instead?
I attempted to do this with enlisting it but I was unable to get it working. Any attempt to use enlist resulted in the fields not appearing.

The $text widget is specifically intended to avoid wikification. You’ll probably want to use $transclude instead, e.g.

\define systemFields() draft.title draft.of title tags text created creator modified modifier

\function display.field.name() [<selectedFields>search-replace:g[-],[ ]sentencecase[]]

<table class="tc-max-width">
	<tbody>
		<$list filter="[all[current]fields:exclude<systemFields>sort[]]" variable="selectedFields">
			<tr>
				<th> <<display.field.name>> </th>
				<td> <$transclude field=<<selectedFields>> /> </td>
			</tr>
		</$list>
	</tbody>
</table>
1 Like

You know, I tried to use transclude once already but in doing so it froze my whole browser and caused a crash, so I assumed that was the wrong approach.

Sidenote, I like the small adjustment you made for displaying the field names! I haven’t seen the g paraeter used for search-replace before, that’s pretty handy.

Thank you for the help :grinning_face_with_smiling_eyes:

2 Likes

I’d forgotten (or perhaps never realized?) that the fields operator could take suffixes, so thank you for reminding me of that!