Message tm-open-window template can't access global Macros

Is this a bug, or just an unexpected feature?

If you open a window with message tm-open-window using a template, the template can’t access global macros.

To see this, add code like:

<<tag "HelloThere">>

<<list-links "[tag[HelloThere]]">>

to the bottom of SampleWindowTemplate at tiddlywiki.com , and then run this launch code from a tiddler:

<$button>Open Window
<$action-sendmessage 
  $message="tm-open-window" 
  $param="$:/temp/openme" 
  template="SampleWindowTemplate" 
  windowTitle="My Window Title"
  width="640"
  height="480"
  something="This is my new window. There are many like it, but this one is mine." />
</$button>

This code was taken from tiddler WidgetMessage: tm-open-window, but don’t use it’s launch bottom there – it doesn’t do anything! (which is another issue).

When the window launches, it will not contain the results of the inserted macro code.

In order to get the macros to work, you have to import them at the top of the template. Which is unexpected for global macros, at least to my way of thinking.

What a surprise. I just stumbled upon the same problem. I also noticed: If I open a window by the menu (Open in new Window) my procedure is called as expected without importing.

Definitely not a bug. When you don’t specify a template, the core default template is used ($:/core/templates/single.tiddler.window) which imports all globals.

If you specify your own template, you then have complete control over whether globals are imported or not. If you want globals available in your template, just add this pragma:

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

But unexpected, right? Because we don’t need this step when using other templates (e.g. list widget) and because it’s not documented. I was not previously aware that there was any way to create a variable-free environment (though why I would ever want this is unclear).

Thanks!

Something similar can be done through the story and/or body cascades. If you replace the use of the existing view template etc…

Note you may also want to import other tagged tiddlers selectively.

  • $:/tags/Macro/View
  • $:/tags/Macro/View/Body
  • $:/tags/Global/View
  • $:/tags/Global/View/Body