Macro failure case study involving tiddler opened in new window

NOTE: although the problem is solved, TiddlyWiki documentation needs improvement regarding the import pragma (circumstances which require the import pragma.)

This should probably be either fixed or documented (or documentation made easier to find if already existing.)

Download the attached and drag into some TiddlyWiki instance.

Take a look at:

  • The “Hello World Macro” tiddler
  • The “Hello World Macro Call” tiddler to see the results ot the macro call and (for later sanity check) the “now” macro call
  • The “HW Viewer Open Button” tiddler with a button to open “Some Tiddler” in a new window, using “Hello World Macro Call” as the template
  • The “Some Tiddler” tiddler

Press the button and we see that the macro reference does not happen. The “now” macro reference works A-1.

This shows a scenario in case custom-created macros will not work.

For my “meaty” use case scenario, I’ve decided best to not use macros and instead stick to transclusions.

Does anybody have a workaround to get the macro working in the scenario here?

Regardless, there should be some heads-up documentation (o rmore noticeable documentation) that warms about the problem with this scrnario.

Macro_Failure_Scenario.json (719 Bytes)

1 Like

@Charlie_Veniot

I have reproduced the result but wonder if there is another way to do what you want. My feeling is there are two or more factors you are not aware of causing this outcome.

A few notes;

  • The “HW Viewer Open Button” uses template="Hello World Macro Call means we do not see the content of “Some Tiddler”.
  • The default behaviour of “open in new window” is to not to render the view template items, only the text field.
    • perhaps this is why you made the template = “Hello World Macro Call”

    • That is why I made buttons to support the full display and edit within a new window new-windows.json (13.3 KB)

Can you describe the ultimate desired income from this structure you shared?

Much too complicated for me to explain the architectural needs and design of what I’m doing. (I can’t explain the design of BASIC Anywhere Machine, and the rational behind the design for the last 7 months of work.)

Way too overwhelming to explain for my abilities.

Which is why I’m trying to simplify communications with the small test case here. So we can just focus on the small technical issue without having to delve into the mass of details of why I’m trying to do this type of macro call in this scenario.

Forget that “Some Tiddler” has nothing in it. For what I’m doing in BASIC Anywhere Machine, the tiddlers represented here by “Some Tiddler” have all kinds of content handled by tiddlers (the BASIC Console Window, and the BASIC Anywhere Machine "Wikify Viewer) represented here by “HW Viewer”

I’ve got a workaround for what I need to do with transclusion instead of macros. Which is fine by me because I prefer transclusions (EDITED: ARG! Mistakenly wrote “macros” instead of "transclusions!!!).

But for the users of BASIC Anywhere Machine, I’d prefer give them the ability to make a macro call embedded in BASIC programs.

So back to focusing on this test case, I want to know what I have to do to make the macro work in the scenario of this test case.

Why does the now macro work but the HelloWorld macro doesn’t?

If it is technically impossible because TiddlyWiki internals can’t handle it, then it should be noted in the documentation somewhere. Something along the lines of because of limitations, TiddlyWiki tiddlers opened in a new window using a template, the template must not involve macros.

@Charlie_Veniot I understand the problem you face extracting an example from a larger piece of work. I will try and find something but It may be too hard to contextualise.

I just need sufficient information to define the problem and the flexibility for work arounds.

  • Global Macro “HelloWorld” defined in “Hello World Macro”
  • Test tiddler “Hello World Macro Call” demonstrates viewing the use of <<HelloWorld>> and <<now>> macros in the story river and is used in
  • HW Viewer Open Button, A button that “attempts” to open “Some Tiddler” in a windows with the template=“Hello World Macro Call”
  • Some Tiddler, an existing tiddler with not other content used in above open in windows button

The <<now>> macro works because it is defined as a “javascript macro” (see shadow $:/core/modules/macros/now.js). As such, it has type=application/javascript and module-type=macro, and is automatically loaded at startup, and thus doesn’t need to be tagged with $:/tags/Macro.

However, unlike the <<now>> macro, your “Hello World” macro is a normal wikitext-based macro (using \define ...), which needs to be tagged with $:/tags/Macro and is only made globally available when the $:/core/ui/PageTemplate is rendered, which contains the following line:

\import [[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]]

The problem you are observing arises because the separate window you are opening doesn’t apply the TWCore PageTemplate, so your macro never gets loaded. To fix this, all you need to do is to add the \import pragma shown above into your “Hello World Macro Call” template.

enjoy,
-e

1 Like

Please, I don’t want a workaround. I have a transclusion workaround for the specified architecture.

I want an explanation of why the macro is not working, and how to make that macro work.

If it is not possible to make that macro work, then I’ll use transclusion.

This is just one of those once in a blue moon situations in which I’d prefer to use a macro.

As per the test scenario. No change to the architecture. Just whatever small tweaks to make the macro work with the specified architecture in the attached scenario.

That is exactly what I was looking for. Thanks Eric, much appreciated.

As soon as I can get around to testing with that import pragma, I’ll report the results back here and mark this thread as resolved.

I much prefer to give BASIC programmers the ability to include BASIC libraries of code via <<include "this.BAS">> rather than {{this.BAS||include}}.

And that was what I was looking for as well for you (the answer Eric gave) :nerd_face:

Yup, that definitely worked.

Now, BASIC Anywhere Machine programs can include code with a somewhat familiar include directive:

<<include "this source code">>

Since I had it working previously, might as well keep the alternative include directive:

{{this source code||include}}

Much appreciated. That was driving me bonkers.

Relevant update for this topic. With Tiddlywiki 5.3.X we now have additional tags used for macros so a comprehensive import pragma is now;

\import [[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]] [all[shadows+tiddlers]tag[$:/tags/Global]!has[draft.of]] [all[shadows+tiddlers]tag[$:/tags/Global/View/Body]!has[draft. Of]] 

The recommended way to import the global macros is with the following pragma:

\import [subfilter{$:/core/config/GlobalImportFilter}]

The current value of $:/core/config/GlobalImportFilter is:

[[$:/core/ui/PageMacros]]
[all[shadows+tiddlers]tag[$:/tags/Macro]!is[draft]]
[all[shadows+tiddlers]tag[$:/tags/Global]!is[draft]]

$:/core/config/GlobalImportFilter should not be modified by users because it might be modified by a future core update.

1 Like

@jeremyruston I imagine when opening a new window that may use other macros and procedures etc… we also need to import the following;

[all[shadows+tiddlers]tag[$:/tags/Global/View]!has[draft. Of]]
[all[shadows+tiddlers]tag[$:/tags/Global/View/Body]!has[draft. Of]]
[all[shadows+tiddlers]tag[$:/tags/Macro/View]!has[draft. Of]]
[all[shadows+tiddlers]tag[$:/tags/Macro/View/Body]!has[draft. Of]]

I addition to $:/core/config/GlobalImportFilter