Is this a bug: Using conditional view widget to show caption or title

172 views
Skip to first unread message

Mohammad

unread,
Jan 4, 2019, 3:18:46 AM1/4/19
to tiddl...@googlegroups.com
I have a macro as below to show the title or caption of a tiddler based on the availability of caption field

\define mac(tid)
[<$view tiddler=$tid$ field="caption">
<$view tiddler=$tid$ field="title"/>
</$view>]
\end

Then I have several tiddlers like t-2016, t-2017, t-2018, t-2019. The two tiddler t-2017 and t-2018 also have c-2017 and c-2018 as caption.

Using the above macro as below gives the below results

Note <<mac t-2017>> and <<mac t-2018>> and <<mac t-2019>> and  <<mac t-2016>> give different result.

Result:

Note [c-2017] and [c-2018] and [ t-2019 ] and [ t-2016 ] give different result.

As you can see extra spaces are inserted when title is shown! What is the problem.

--Mohammad

Mohammad

unread,
Jan 4, 2019, 3:30:38 AM1/4/19
to TiddlyWiki
I could solve the issue by removing the line breaks as below


\define mac(tid)
[<$view tiddler=$tid$ field="caption"><$view tiddler=$tid$ field="title"/></$view>]
\end


But why line breaks here interpreted as space?

--Mohammad


Mohammad

unread,
Jan 4, 2019, 3:42:01 AM1/4/19
to TiddlyWiki
See Jeremy answer to this question here:GitHub

Seems this is not a bug and depends to browser.


--Mohammad

S. S.

unread,
Jan 4, 2019, 5:18:09 AM1/4/19
to TiddlyWiki

Mohammed,

As a precaution, you may want to read this explanation on github by Jeremy of using the caption field vs. the title field.

... the caption field is generally wikified (and so can include formatting etc.) while the title is rendered as plain text.

Thus you may prefer something on the lines of:

<$list filter="[all[current]has[caption]]"
      emptyMessage="""<$view field="title"/>""">
      <$transclude field="caption"/>
</$list>

Regards.

Mohammad

unread,
Jan 4, 2019, 5:27:17 AM1/4/19
to TiddlyWiki
Good point S. S,
 Yep, this is good to apply formatting to caption.

Cheers
Mohammad

TonyM

unread,
Jan 4, 2019, 5:31:23 AM1/4/19
to TiddlyWiki
Mohammad,

If the purpose of this macro is to show the caption then if not existing the title then there is now a more elegant way.

<$list filter="[all[current]has[caption]get[caption]] ~[{!!title}]"></$list>

However this returns a tiddler link even to the caption

So Try this
<$list filter="[all[current]has[caption]get[caption]] ~[{!!title}]" variable=name>
<$link to=<
<currentTiddler>> tooltip="Custom tooltip"><<name>></$link>
</$list>

Or make a macro
\define caption-title()
<$list filter="[all[current]has[caption]get[caption]] ~[{!!title}]" variable=name>
<$link to=<<currentTiddler>> tooltip="Custom tooltip"><<name>></$link>
</$list>
\end

and use <<caption-title>> no paramters to always show first the caption, then the titlewith an active link.

Regards
Tony

Mohammad

unread,
Jan 4, 2019, 5:47:08 AM1/4/19
to TiddlyWiki
Hi Tony,

 Clever solution. I bookmark this solution.

By the way as S. S above indicated there is some confusing cases with toc-macro uses caption/title when caption is not existed or empty.
For my case, I need to remove the extra spaces when caption is used, and I realized that is because line breaks in my code!  See my first post above.

--Mohammad

TonyM

unread,
Jan 4, 2019, 5:56:09 AM1/4/19
to TiddlyWiki
Mohammad,

I have seen this extra leading and trailing space issue a few times. This is in part why I use the method I proposed which uses the link widget to create the link.

Others have suggested passing such values with leading and trailing spaces to another macro to "sanitise them" eg if parameter is the value returned (Without brackets but leading and trailing spaces.)

<<macro parameter>>
\define macro(input) [$Input$]

Regards
Tony

Mohammad

unread,
Jan 4, 2019, 6:39:04 AM1/4/19
to TiddlyWiki
Thanks for the hint!

Cheers
Mohammad

Thomas Elmiger

unread,
Jan 4, 2019, 5:49:29 PM1/4/19
to TiddlyWiki
Hi folks,


... the caption field is generally wikified (and so can include formatting etc.) while the title is rendered as plain text.

An even shorter solution for this:

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

Thanks for the hints!
Thomas

Thomas Elmiger

unread,
Jan 4, 2019, 6:27:23 PM1/4/19
to TiddlyWiki
And one more, this one omits automatic linking to CamelCase captions:

<$view field="caption" format="plainwikified"><$view field="title" format="text" /></$view>

Have fun,
-t

TonyM

unread,
Jan 4, 2019, 6:50:20 PM1/4/19
to TiddlyWiki
Info for all and thanks Thomas


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).

Explains why 
<$transclude field="caption"><$view field="title"/></$transclude>
works

Of note here is we are asking to transclude a field, not a whole tiddler, and this is a form of emptyValue

This actually is a great tip because it provides a form of selective display, a block of wiki text can be displayed, simpler to use than list or reveal, that operates on the existence of a value, not yes or no.

Regards
Tony

Mohammad

unread,
Jan 4, 2019, 9:27:22 PM1/4/19
to TiddlyWiki
Thanks Thomas, Thanks Tony
It is a pity, we have not good documentations on these.

There are alots to do with TW scripting, but few people know, AND nobody knows all of them.

Mohammad

S. S.

unread,
Jan 5, 2019, 1:39:38 AM1/5/19
to tiddl...@googlegroups.com
Hi Thomas,

I still can't find a better way than:

<$list filter="[all[current]has[caption]]"
      emptyMessage="""<$view field="title"/>""">
      <$transclude field="caption"/>
</$list>

The problem with the below is that if there is a caption field, but it is empty, nothing will show. I find that unacceptable. This was the exact issue I tried to have fixed (on github) but that hasn't been resolved because of possible performance issues in a large table of contents.


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

The problem with the next one below is that it does not apply wikitext formatting - for example if the caption is: πr^^2^^


<$view field="caption" format="plainwikified"><$view field="title" format="text" /></$view>

It would be nice if the issue could solved somehow, perhaps by adding a format="wikified" for the $view widget.

Regards.

S. S.

unread,
Jan 5, 2019, 2:04:59 AM1/5/19
to TiddlyWiki
Hi Tony,

I believe the fallback is not exactly emptyValue for a field's value - because if there is the field but it has no value - the TranscludeWidget will return empty. It is only if there is no field - that the fallback can be used. However, it appears it can be used by looking for the existence of a tiddler.

Cheers.

Thomas Elmiger

unread,
Jan 5, 2019, 5:29:36 AM1/5/19
to tiddl...@googlegroups.com
Hi S.S.

Thank you for pointing out the weaknesses (and strengths) of my suggestions! That led me to the following hack:

<$link tooltip={{!!title}}><$transclude field="caption"><$view field="title"/></$transclude>&nbsp;</$link>

The non breaking space &nbsp; makes sure that I can see the link in my list, even if it contains no text.

Have a great weekend!
Thomas

TonyM

unread,
Jan 5, 2019, 6:29:00 PM1/5/19
to TiddlyWiki
S S,

Sorry, my above comment was somewhat off topic. It was drawing out the behaviour that Thomas pointed out, with the transclude widget.

If we use the existence of a field as an indicator, then if it has a value or not may not matter. If the field does not exist (and thus cant have a value) the the fall back could display the code necessary to create that field. Just a possible mechanism that may be of use. If the field has a value it will return it, which is not allways desirable.

Regards
Tony

Mohammad

unread,
Jan 9, 2019, 3:27:54 AM1/9/19
to tiddl...@googlegroups.com
Hello S. S.
I understood your solution is the complete one!
The question is if I use this code in rather large wiki (12000 tiddlers) what would be the impact of using
$list widget here?

Have made a benchmarking to see how lengthy is the above computation time to show the results?


--Mohammad

Mohammad

unread,
Jan 9, 2019, 3:59:30 AM1/9/19
to TiddlyWiki
Tony!
 In your solution below

<$list filter="[all[current]has[caption]get[caption]] ~[{!!title}]" variable=name>
<$link to=<
<currentTiddler>> tooltip="Custom tooltip"><<name>></$link>
</$list>

Isn't it correct to change  to=<<currentTiddler>> to to=<<name>>? What does it mean when it is used is used inside a list widget with defined variable? It refer to hosting tiddler.


--Mohammad
Reply all
Reply to author
Forward
Message has been deleted
0 new messages