showing a section of text from a template only when the field is present

62 views
Skip to first unread message

MissyLaMotte

unread,
Nov 27, 2020, 2:27:24 PM11/27/20
to TiddlyWiki

Hi,

I am relatively new to TiddlyWiki (I did use the classic version before, though) and I am trying to find my way around. Here is what I am trying to do.

I am writing a novel and I want to keep my character list in a TiddlyWiki. I made a template for how I want my character information to be shown, using fields. For a new character I then just fill out all desired fields and transclude it into the template. It works fine, so I think I have the general mechanism down. Now, some fields don't apply for all characters, so they can be left empty. in that case, I would like to be able to hide that portion of text.

So, in my template I have something like:
Name: {{!!char_name}}, alias: {{!!alias}}

on my actual Charakter tiddler I only have the field char_name, but not alias, so it renders to
Name: John Doe, alias:

and I would like to find a way to hide the ",alias: " part completely in that case. I have a feeling it can be done with filters and (has then else) somehow, but I don't get the syntax correct. Can anyone with more experience help me out, please?

Thanks,
Jutta

Eric Shulman

unread,
Nov 27, 2020, 2:49:17 PM11/27/20
to TiddlyWiki
On Friday, November 27, 2020 at 11:27:24 AM UTC-8 jutta....@googlemail.com wrote:
in my template I have something like:
Name: {{!!char_name}}, alias: {{!!alias}}
on my actual Charakter tiddler I only have the field char_name, but not alias, so it renders to
Name: John Doe, alias:
and I would like to find a way to hide the ",alias: " part completely in that case.

Try this:
{{!!char_name}}<$list filter="[<currentTiddler>has[alias]]">, alias: {{!!alias}}</$list>

Notes:
* the has[alias] operator only returns the currentTiddler if the alias field is non-blank
* if you wanted to allow a blank alias field (but still require the field to exist), use has:field[alias] instead

enjoy,
-e 

MissyLaMotte

unread,
Nov 28, 2020, 5:45:12 AM11/28/20
to TiddlyWiki
Fantastic, that was exactly what I needed. Works like a charm. Thank you very much.
Reply all
Reply to author
Forward
0 new messages