Lost in transclusion

150 views
Skip to first unread message

Werner

unread,
Aug 18, 2020, 1:06:59 PM8/18/20
to TiddlyWiki
Once again, I am feeling like a complete dumbass when dealing with transclusion and substitution. Still having a hard time with it. OK, here's the code:


I am refering a tiddler called activeDossier whose contents refers to a JSON data tiddler. Tiddler content is {{$:/data/CI/companyRegister##1/name}}. What I basically want to do is auto-generating company dossiers, coming from various sources in my database. I have a list of companies as JSON from which I can select. This works up to the point below
 
<$set name="theCompany" value={{$:/data/CI/activeDossier}}>

!<$vars tv-wikilinks=no><<theCompany>></$vars> <!-- gets displayed properly -->

<$list filter="[!is[system]search<theCompany>]" >
<<currentTiddler>>
</$list>

</$set>

My problem is: the variable "theCompany" seems to be properly assigned, at least it gets displayed properly, so what am I doing wrong when I want to assign it to the list filter. I suspect, something along the transclusion chain is going wrong here, but I need someone to point me at it and how to find a remedy.

Thanks to all helpful souls. 

Mat

unread,
Aug 18, 2020, 1:30:08 PM8/18/20
to TiddlyWiki
It might be as simple as needing to use triple quoting, in case your theCompanies have quote characters in them.

But note that the filter [!is[system]search<theCompany>] refers to all tiddlers globally, not e.g the current tiddler if that is what you hope for. IF you want to test if theCompany !is[system] you must do e.g [<theCompany>!is[system]... etc.

<:-)

Mark S.

unread,
Aug 18, 2020, 1:43:45 PM8/18/20
to TiddlyWiki
It looks like you want to search the text, title, or tag field for the name of a company?? Is that what you want? If you want to search in some non-default field, then you need to specify that field in your search.

Werner

unread,
Aug 18, 2020, 3:42:14 PM8/18/20
to tiddl...@googlegroups.com
Hi Mat, yes, I want to search globally. A pretty basic search on all text and title fields. Oh, and no quotes in company names.

Werner

unread,
Aug 18, 2020, 3:43:25 PM8/18/20
to TiddlyWiki
Hi Mark, yes, as written to Mat, title and text will do.

Eric Shulman

unread,
Aug 18, 2020, 5:15:51 PM8/18/20
to TiddlyWiki
On Tuesday, August 18, 2020 at 10:06:59 AM UTC-7, Werner wrote:
I am referring to a tiddler called activeDossier whose contents refers to a JSON data tiddler. Tiddler content is {{$:/data/CI/companyRegister##1/name}}.

<$set name="theCompany" value={{$:/data/CI/activeDossier}}>
!<$vars tv-wikilinks=no><
<theCompany>></$vars> <!-- gets displayed properly -->
<$list filter="[!is[system]search
<theCompany>]" >
<
<currentTiddler>>
</$list>
</$set>

The problem is that you are doing a "double transclusion".  That is, the value of <<theCompany>> retrieved via transclusion isn't the actual name of the company as text, but rather a secondary transclusion from a JSON tiddler (i.e., {{$:/data/CI/companyRegister##1/name}}).  When you render <<theCompany>>, TiddlyWiki automatically parses that transclusion and displays the actual value.  However, when you use search<theCompany> in the filter, the value isn't parsed any further, and you are literally searching for the transclusion syntax, not the actual company name as text.

To resolve this, use <$wikify> instead of <$set> to fetch theCompany value, like this:
<$wikify name="theCompany" text={{$:/data/CI/activeDossier}}>
!<$vars tv-wikilinks=no><
<theCompany>></$vars> <!-- gets displayed properly -->

<$list filter="[!is[system]search
<theCompany>]" >
<
<currentTiddler>
>
</$list>
</$wikify>
The $wikify gets the value from the activeDossier tiddler AND then also parses that value, so the result is the desired text value from the underlying $:/data/CI/companyRegister tiddler.

When you use it in the search<theCompany> filter, it's already fully resolved to be the actual company name as text, so the search should work as you intend.

-e

TW Tones

unread,
Aug 18, 2020, 7:47:32 PM8/18/20
to TiddlyWiki
Werner,

I am confident Eric is spot on. It was the correct understanding of this issue and the use of wikify that stopped me getting stuck regularly. I have being trying to get some activity on this because it is a barrier to new users. Perhaps this quick note will help as a rule until you fully understand it.
  • If you need a value to be "evaluated" from wikitext to use within subsequent Wikitext logic use the wikify widget at the last possible moment.
    • This guide suggests trying to use wikify in external macros is a path to disappointment
  • Make sure you close the wikify appropriately (as with all other widgets) or unusual and broken result will occur
  • Its only at the final render of the tiddler that all things are wikified automatically so a standalone `<<varormacro>>` appears to produce the result you want, but as Eric said the result inside the wikitext (before evaluation) without wikification it is not evaluated at that point.
  • It is fine to use the same name when wikifying to stop code complexity
\define macroname() blah blah
<$wikify name=macroname text="<<macroname>>">
   
use <<macroname>> here where it is the wikified version, or pre-evaluated
</$wikify>

In closing
  • If some of our community developers see this what would be better is something like the following;
    • Allow any variable to be referenced in its "evaluated state" eg ((macroname)) would effectively wikify inline
    • Automatically wikify/evaluate variables or macros when used in filters and other appropriate places.
Regards
Tones

Werner

unread,
Aug 19, 2020, 5:03:56 AM8/19/20
to TiddlyWiki
Thanks so much, Eric and Tony. As usal, this was extremely helpful. And <$wikify> actually solved the issue. 

In fact, I was assuming the transclusion chain had to do with it (hence the thread title), I am just not literate enough in TW to draw the right conclusions and find the remedies. But I keep on working at it.

Which brings me to another point: maybe I've overcomplicated things by storing a transclusion in a tiddler where a pointer to an array index in the JSON tiddler (i.e. a number) should have done the trick. But that's a different story.

So, thanks again, guys, much appreciated.

Ed Heil

unread,
Aug 20, 2020, 8:55:10 AM8/20/20
to TiddlyWiki
....and the wikify widget is finally, for the first time, clear to me. Thanks!
Reply all
Reply to author
Forward
0 new messages