Help Wanted - Filtered transclusion

121 views
Skip to first unread message

TW Tones

unread,
Nov 8, 2020, 7:25:07 PM11/8/20
to TiddlyWiki
Folks,

I can work out what is happening here, at least a second set of eyes would be appreciated

I have a filtered transclusion as follows
{{{ [<local-value>] ~[<global-config-value>] ~[<config-default>] }}}

Each of the variables therein are set using a $set widget (more details below)

Unfortunately the second result global-config-value is never the result if there is no local-value

The following is how I get the global-config-value and it works as below
<$set name=config-tiddler value={{{ [[$config-name$]addprefix[$:/config/]] }}}>
<$set name=global-config-value value={{{ [
<config-tiddler>get[text]] }}}>


:global-config-value=<
<global-config-value>><!--returns the correct value here but never responds to this value in the filtered transclusion.
Yet when I try and use the filtered transclusion above, specifically  ~[<global-config-value>]
It never seems to work.
I have tried to wikify the value first with no success

I have looked at this many times and cant see what is wrong.

Thanks in advance if you can help

Tones


Eric Shulman

unread,
Nov 8, 2020, 8:54:10 PM11/8/20
to TiddlyWiki
On Sunday, November 8, 2020 at 4:25:07 PM UTC-8, TW Tones wrote:
I have a filtered transclusion as follows
{{{ [<local-value>] ~[<global-config-value>] ~[<config-default>] }}}
Each of the variables therein are set using a $set widget (more details below)
Unfortunately the second result global-config-value is never the result if there is no local-value

You have three runs, using an implied "OR", with the expectation that they are evaluated left-to-right, until a value is found.
I'm not 100% certain why the above syntax doesn't do that.  But you might try using else<...> instead:

{{{ [<local-value>else<global-config-value>else<config-default>] }}}

-e 

TW Tones

unread,
Nov 9, 2020, 12:48:07 AM11/9/20
to TiddlyWiki
Eric,

Thanks for the suggestion But it has not solved it. It is almost as if when used in the filter else goes bad

This proves the values are being populated
:1 {{{ [<local-value>] }}}
:2 {{{ [<global-config-value>] }}}
:3 {{{ [<config-default>] }}}

But something is still going wrong as all three of these return the value in <<local-value>>
1: {{{ [<local-value>] }}} returns a value is set
4:{{{ [<local-value>else[other]]  }}}
5:{{{ [<local-value>] ~[[other]]  }}}

Weird

Tones

Saq Imtiaz

unread,
Nov 9, 2020, 1:12:54 AM11/9/20
to TiddlyWiki
How are you setting
<local-value>

?

I suspect it never returns an empty list, and therefore the else clause is never triggered.

For example, the following will never trigger an else clause when used in a filter, as it will never return an empty list:
<$set name=config-tiddler value={{{ [[$config-name$]addprefix[$:/config/]] }}}>

Assuming that each filter run returns an empty list when it should not be used, you can also use the form:
{{{ [<local-value>] [<global-config-value>] [<config-default>] +[first[]] }}}

TW Tones

unread,
Nov 9, 2020, 9:05:51 PM11/9/20
to TiddlyWiki
Saq,

Thanks fort the tip, yes I tried that. I will review again with a fresh look, but it is confusing me.

I am wondering if there is some sort of regression or bug here?

I suppose in the mean time if I can find an alternative, perhaps with list filters and not filtered transclusions it would be fine, however it does seem like a source of hours of frustration.

I will share back any learnings.

Without solving why the former did not work this is a working version.
\define get-config(name)
{{{ [all[current]get[$name$]] ~[[$:/config/$name$]get[text]] ~[[$:/config/$name$]get[config-values]split[ ]first[]] }}}<br>
\end
<<get-config test-config>>

However from experience if I wish to access the result in a list filter I will first need to wikify  
<<get-config test-config>>

Which makes the code messy.

Regards
Tones

Saq Imtiaz

unread,
Nov 9, 2020, 10:50:25 PM11/9/20
to tiddl...@googlegroups.com
You may have missed my point. I don't believe your first filter run ever returns an empty title list.

Try this:
{{{ [<local-value>!is[blank]] ~[<global-config-value>!is[blank]] ~[<config-default>] }}}

For a hint try this in Advanced Search -> Filters:
[<foo>]
It should tell you there is 1 match.

You can also test:
{{{ [<local-value>count[]] }}}

Your first filter run must return no titles in order for the else clause to be triggered.

If none of that works, please post the actual vs expected outcome of:
{{{ [<local-value>] [<global-config-value>] [<config-default>] }}}

TW Tones

unread,
Nov 10, 2020, 6:16:31 PM11/10/20
to TiddlyWiki
Saq,

Thanks, I did understand your point, and expected <local-value> to be empty and could not make it so, Although '<<local-value>>' always returned '' when empty.
But as I read in the following example it appears to be blank? thus if !is[blankno value will be returned and else is engaged.

Perhaps we can say an empty run is blank not empty?
Thus as you suggested !is[blank] changes blank to empty.

Thus in the case of [<varname>] an empty varname returns blank not empty.

I have decided to take another path, dynamically create a macro eg "\define setting() value"

This reply was Posted now, I forgot to post it yesterday.

Thanks for you help
Tones

Saq Imtiaz

unread,
Nov 10, 2020, 6:28:24 PM11/10/20
to TiddlyWiki
The key thing to understand here is that unknown variables get assigned a value of "", i.e. a zero length string. The is[blank] operator checks specifically for zero length strings.

So <<missingvar>> won't show anything when wikified as you are rendering a zero length string, but the filter result is not an empty title list but rather has one member, a zero length string.
Reply all
Reply to author
Forward
0 new messages