displaying caption IF there is one, title if not

187 views
Skip to first unread message

Michael Gentry

unread,
Mar 20, 2018, 9:19:47 AM3/20/18
to TiddlyWiki
Is there a compact way to display a tiddler's caption IF it has one, defaulting to its title if the caption field does not exist or is empty?

Ton Gerner

unread,
Mar 20, 2018, 9:34:28 AM3/20/18
to TiddlyWiki
Hi Michael,

Try

<$transclude field="caption">
<$view field="title"/>

Cheers,

Ton

Michael Wiktowy

unread,
Mar 20, 2018, 10:12:33 AM3/20/18
to TiddlyWiki
Unless you wrap the <$view field="title"/> in a RevealWidget that matches on a blank ("") caption field, you will display both when a caption field is present.

<$transclude field="caption"/>
<$reveal type="match" value={{!!caption}} text=""><$view field="title"/></$reveal>

Note that a lot of things (TOC headings and Tab Titles) do this by default. So you can dig into those macros to maybe find a more efficient way

/Mike

Mark S.

unread,
Mar 20, 2018, 10:28:44 AM3/20/18
to TiddlyWiki
I think if you try it you'll see that Ton's method works. It's one of those undocumented features of how the widgets work. If the widget doesn't evaluate to anything, then the inner contents are used.

Jeremy Ruston

unread,
Mar 20, 2018, 10:40:44 AM3/20/18
to tiddl...@googlegroups.com
I think if you try it you'll see that Ton's method works. It's one of those undocumented features of how the widgets work. If the widget doesn't evaluate to anything, then the inner contents are used.

The behaviour is documented, but perhaps is unclear (https://tiddlywiki.com/#TranscludeWidget):

The TranscludeWidget treats any contained content as a fallback if the target of the transclusion is not defined (ie a missing tiddler or a missing field).

Best wishes

Jeremy.



On Tuesday, March 20, 2018 at 7:12:33 AM UTC-7, Michael Wiktowy wrote:
Unless you wrap the <$view field="title"/> in a RevealWidget that matches on a blank ("") caption field, you will display both when a caption field is present.

<$transclude field="caption"/>
<$reveal type="match" value={{!!caption}} text=""><$view field="title"/></$reveal>

Note that a lot of things (TOC headings and Tab Titles) do this by default. So you can dig into those macros to maybe find a more efficient way

/Mike

On Tuesday, March 20, 2018 at 9:34:28 AM UTC-4, Ton Gerner wrote:
Hi Michael,

Try

<$transclude field="caption">
<$view field="title"/>

Cheers,

Ton


-- 
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/c304780b-67c1-4fc7-b3d0-1dfebfc7776d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jed Carty

unread,
Mar 20, 2018, 10:56:26 AM3/20/18
to TiddlyWiki
Ton's method is correct, but his post is missing the closing tag for the transclusion.

<$transclude filed='caption'>
<$view field='title'/>
</$transclude>


I just want to add that using transclude wikifis the content of the caption field, if you don't want that for some reason you can use this instead:

<$view field='caption'>
<$view field='title'/>
</$view>



And this is documented behaviour for both widgets

Michael Wiktowy

unread,
Mar 20, 2018, 11:05:48 AM3/20/18
to TiddlyWiki
Really good information! Thanks for clarifying. I have a lot of messy RevealWidgets to strip out of my Tiddlers. :]

Is the rendering different due to the <$view> widget use the "format" specified in the tag for the empty message?

Also, looking at the fine print in the description, it is true that <$transclude> empty message is triggered on missing fields while <$view> empty message is triggered on missing *or* empty fields?

/Mike
Reply all
Reply to author
Forward
0 new messages