My Transclusion headache

132 views
Skip to first unread message

TonyM

unread,
Jul 15, 2017, 10:18:03 PM7/15/17
to TiddlyWiki
Folks,

I am still struggling with the multiple layers of transclusion. Rather than detail the complex (for me) problem, I was wonderd someone can tell me how to do something I consider should be simple.

Using field values in my primary tiddler, how can I construct a variable, that once set in the primary tiddler will retain its value in all subsequently transcluded tiddlers, including macros etc... I want to pass a value to subsequent lists etc... that is not reevaluated in every other tiddler/macro/filter etc...

Is there an answer?, because if it isI  expect I can proceed with what I am building before I become expert in transclusion. For me this is an example of a barrier to more advanced uses, in someways I need to know everything before I can learn something, so I can start to learn everything.

Thanks in advance
TonyM

PMario

unread,
Jul 16, 2017, 8:05:47 AM7/16/17
to TiddlyWiki
Hi Tony,

I think, you are mixing up fundamentally different things (fields, variables and macros), and that gives you a headache. I'll try to point you into the right directions.


On Sunday, July 16, 2017 at 4:18:03 AM UTC+2, TonyM wrote:
Using field values in my primary tiddler,

Fields are an integral part of the tiddler. So whenever you access eg: HelloThere all the fields that are defined with it, are also there. Fields always live in the context of the current tiddler.

eg:
HelloThere has a "list-field" ... You can access this field from everywhere with {{HelloThere!!list}}

If you want to transclude the "text-field" you can use {{HelloThere!!text}}

Because we are lazy folks, we don't want to type too much there is a convenient function built in to TiddlyWiki: "whenever a transclusion is specified, the text field is used as the default field value." So we can write: {{HelloThere}} if we want the content.

Sometimes we don't want to specify the tiddler title, because it should be dynamic. So we want to use: {{!!list}}. TW has a problem now. The tiddler title is not defined anymore. ... That's why a sensible default is used: The  <<currentTiddler>> variable. This currentTiddler variable is set by the ViewTemplate, with the tiddler widget.

The transclude-widget uses the currentTiddler variable, but doesn't set it! That's important!!!!

Let's create 2 test tiddlers: outer and inner. Where outer is the primary tiddler, that transcludes the inner tiddler. The inner tiddler want's to access the primary-field ... That's what you want. right?

outer  .... defines a field eg: primary-field: PRIMARY
outer:text

outer: {{!!primary-field}}

inner: {{inner}}


-----
inner

{{!!primary-field}}


----------------

This doesn't work, because {{inner}} sets the currenTiddler variable to "inner". So we need to change outer to:

outer:

inner: {{||inner}}
or
inner: <$transclude tiddler=inner/>

So the currentTiddler variable isn't changed and the inner tiddler sees the primary-field. We call this mechanism "Transcludion with Templates" .... inner is a template now.

... part 1 .... more to follow

hope that helps a bit
have fun!
mario

PMario

unread,
Jul 16, 2017, 8:10:15 AM7/16/17
to tiddl...@googlegroups.com
 
how can I construct a variable, that once set in the primary tiddler will retain its value in all subsequently transcluded tiddlers,

In TW variables have a scope. ... That means they are only valid inside their scope.

Simple test: If you copy paste the following snippet into an empty tiddler

<<var-test>>
<$set name="var-test" value="asdf">
  <<var-test>>
</$set>
<<var-test>>

Only one "asdf" string is visible!!

Transclusions, that want to work with variables set in a tiddler, have to be called inside the "scope" of the corresponding widget. See the "set-widget" example form above.

outer:

<$set name="var-test" value="asdf">
  <$transclude tiddler="inner"/>
</$set>

inner:

<<var-test>>


The same mechanisms are used by the core templates. ... They are just a bit more "advanced" ;)


part 2 ... one more to follow

have fun!
mario

PMario

unread,
Jul 16, 2017, 8:59:47 AM7/16/17
to TiddlyWiki
 
including macros etc... I want to pass a value to subsequent lists etc... that is not reevaluated in every other tiddler/macro/filter etc...

Once upon a time, there where no global macros.
Macros could only live within the tiddler where they have been defined.
Users felt great pain. They endlessly complained about of their misery.
So a brave hero had to be sent out to defend the dragon ...
uups ... ok ok ...

Since beta 5.0.13 we have the import-variables widget.

outer:

\define my-macro() Praise the hero!


<$set name="var-test" value="asdf">
  <$transclude tiddler="inner" mode=block/>
</$set>



inner:

<$importvariables filter="outer">

<<my-macro>>

</$importvariables>

{{!!primary-field}}

<<var-test>>

hope that helps :)  ... use with care!
and

have fun!
mario

TonyM

unread,
Jul 16, 2017, 9:46:07 PM7/16/17
to TiddlyWiki
Thanks Mario,

I will do my best to understand the consequences of the above.

Where I start to have difficulties is when I try to use values in widgets, macros etc...

I do not expect you to solve my problem but here is my chalenge.

My particular application uses a field in outer with multiple named tiddlers (Like a tags field)
eg tiddlerlist: "Overview examples [[How to]]"
We could call this a list of suffixes

I want to create a new tiddler button (when viewing outer) for tiddlers prefixed by outers (title), suffixed by each value
eg
outer - Overview
outer - examples
outer - How To

The new tiddlers must also be tagged with "outer" their sufix eg Overview and have their field caption set to their suffix value

Idealy you will not see the new tiddler button if the tiddler already exists 

I then have a nice tabs command which only displays tabs of tiddlers with the suffix if they exist

@@.tabsstyle
<div>
<<tabs "[prefix[$(currentTiddler)$ - ]]" "'{{!!defaulttab}}">>
</div>
@@

This will allow me to create tiddlers using outer as a template, which will provide optional tabs and subtiddlers in the tiddler accordiong to the values in tiddler list. Examples may include
Work Instructions
Code Snipits
....

The truth is it is currently beyond my skill level, but I see great potential.

I am sure what you have told me will get me there eventualy.

Regards
Tony

TonyM

unread,
Jul 16, 2017, 9:47:49 PM7/16/17
to TiddlyWiki
P.S.

The line above

<$importvariables filter="outer">

I want to have passed the name outer to inner

Thanks
Tony

On Sunday, July 16, 2017 at 10:59:47 PM UTC+10, PMario wrote:

PMario

unread,
Jul 17, 2017, 12:31:54 AM7/17/17
to TiddlyWiki
On Monday, July 17, 2017 at 3:46:07 AM UTC+2, TonyM wrote:
Where I start to have difficulties is when I try to use values in widgets, macros etc...

I see.
 
My particular application uses a field in outer with multiple named tiddlers (Like a tags field)
eg tiddlerlist: "Overview examples [[How to]]"
We could call this a list of suffixes

ok
 
I want to create a new tiddler button (when viewing outer) for tiddlers prefixed by outers (title), suffixed by each value
eg
outer - Overview
outer - examples
outer - How To

:) Yea ... this is a macro uses variables problem. ... can't be solved with transclusions, ...
 
The new tiddlers must also be tagged with "outer" their sufix eg Overview and have their field caption set to their suffix value

that should be straight forward.
 
Idealy you will not see the new tiddler button if the tiddler already exists 

should be possible.
 
I am sure what you have told me will get me there eventualy.

yes. ... but still some work needed.

I should have some more pointers ... soon.

-m

PMario

unread,
Jul 17, 2017, 8:19:49 AM7/17/17
to tiddl...@googlegroups.com
Hi Tony,

It's all relatively straight forward. .. I think I know, what causes your headaches.

The fact, that you can't do  $(var)${{!!field}} .. It needs to be $(var)$$(secondVar)$ ... to work

The fact, that the list-widget modifies the currentTiddler by default. ... BUT there is a "variable" parameter, which is very handy, but definitely "underused" by new users.

I did add an attachment, that you can analyze.

 - It contains a stylesheet tiddler, to customize the buttons. and
 - a new-set-template template, that is automatically activated, when a tiddler has a "tab-list" field.
 - The buttons are hidden, if the tab-tiddler contains some text! .. So if the tiddler exists, but is empty, the button will be visible.
 - The default tab is Overview except, if the "tab-default" contains a different parameter. .. see the hugo tiddler

have fun!
mario
new-set-template-example.json

PMario

unread,
Jul 17, 2017, 8:22:36 AM7/17/17
to TiddlyWiki
Reply all
Reply to author
Forward
0 new messages