Macros template push variable

Hello,
Here, I have a small problem with a macro in zope.
I define a constant in my macro (tal: define = "global myConst python: 'any'"), but I don't have access to it when I use the macros to build another page.
I've tried using the word "global" to define my constant in my macro, but nothing helps.
Do you have an idea?
Thank you in advance for your help.

Note that macros are incorporated in a two step process. In the first step only metal attributes are processed ; only in the second step are tal attributes processed -- when (and if) the template rendering reaches them. Note that tal attributes defined outside a macro may not be rendered (and therefore processed) at all. You may want to share the relevant parts of your macro and the template using this macro.

When I remember right, then I have seen a global related bug in chameleon. But, I no longer remember the details -- and therefore, I may be wrong altogether. If there was a (simple access) problem, it should be gone in current chameleon versions. Therefore, you should report which versions (Zope, chameleon) you are using.

Hello,
I am using Zope 5.1, and Chameleon 4.8.
here is the code of my macro:

<metal:x define-macro="base">
<!doctype html>
<html lang="fr">
<head>
    
</head>
<body class="bg-black bg-cover bg-no-repeat bg-top overflow-hidden"   tal:define="global T request/SESSION/translation | context/translate/translation.py">
    < div class="w-screen h-screen overflow-x-hidden overflow-y-auto pb-24">
         <tal:x metal:define-slot="base-container">

         </tal:x>
 </div>
< /body>
</html>
</metal:x>

Dans ma macros, ma variable T n'est pas propagé aux composants utilisés dans une page.
Working example:
<metal:x use-macro="context/common/templates/base.html/macros/base">
<metal:x fill-slot="base-container">
<tal:x replace="python:T.get('example')"></tal:x>
</metal:x>
</metal:x>

Example not working:
<metal:x use-macro="context/common/templates/base.html/macros/base">
<metal:x fill-slot="base-container">
<tal:x content="context/anyComponent"></tal:x>
</metal:x>
</metal:x>

Where anyComponent just contain :

<tal:x replace="python:T.get('example')"></tal:x>

Thanks for your help

You cannot use Chameleon 4.8 (because chameleon==3.8.1 is the most recent release).

In older releases (I checked chameleon==3.6), global had no effect: a "global" variable was treated exactly as a "normal" one.

Your example should work even with a "normal" definition of T (i.e. without the global). You might try it out.

Note that chameleon may use a persistent (template) cache. I had the impression (though the chameleon author disagreed) that the cache is not invalidated when the chameleon version changes. This could lead to surprises when you have changed the chameleon version with old templates still in the cache.

I was wrong: your example cannot work: your example "calls" the template anyComponent. Such a call does not inherit the variables of the caller (neither the local nor the global ones); only macros expansions can access those variables.

Indeed, I made a small mistake, it is Chameleon 3.8.1 that I am using.
I redid the tests and the consequences are serious because the code stops my Zope5 instance.
Below is the traceback:

    zope@vps-xxxxxx:~/zope5/instance/var/cache$ 2020-12-18 12:59:42 ERROR     [Zope.SiteErrorLog:252][waitress-2] 1608296382.15398620.09496928904466329 http://XX.XX.XX.XX:8080/TEST/pushBaseMacro.html/ZScriptHTML_tryForm
        Traceback (innermost last):
          Module ZPublisher.WSGIPublisher, line 167, in transaction_pubevents
          Module ZPublisher.WSGIPublisher, line 376, in publish_module
          Module ZPublisher.WSGIPublisher, line 279, in publish
          Module ZPublisher.mapply, line 85, in mapply
          Module ZPublisher.WSGIPublisher, line 68, in call_object
          Module Shared.DC.Scripts.Bindings, line 333, in __call__
          Module Shared.DC.Scripts.Bindings, line 370, in _bindAndExec
          Module App.special_dtml, line 214, in _exec
          Module DocumentTemplate._DocumentTemplate, line 144, in render_blocks
          Module DocumentTemplate._DocumentTemplate, line 245, in render_blocks_
          Module DocumentTemplate.DT_In, line 678, in renderwob
          Module DocumentTemplate._DocumentTemplate, line 144, in render_blocks
          Module DocumentTemplate._DocumentTemplate, line 245, in render_blocks_
          Module DocumentTemplate.DT_Raise, line 76, in render
        zExceptions.Redirect: http://XX.XX.XX.XX:8080/TEST/pushBaseMacro.html
        Fatal Python error: Cannot recover from stack overflow.
    Current thread 0x00007fcdcf7fe700 (most recent call first):
      File "/home/zope/zope5/lib/python3.7/site-packages/zope/tales/expressions.py", line 134 in _eval
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/Expressions.py", line 184 in _eval
      File "/home/zope/zope5/lib/python3.7/site-packages/zope/tales/expressions.py", line 250 in __call__
      File "/home/zope/zope5/instance/var/cache/957a703eb61c3ee0b13514b061f8ac18.py", line 160 in render
      File "/home/zope/zope5/lib/python3.7/site-packages/chameleon/template.py", line 192 in render
      File "/home/zope/zope5/lib/python3.7/site-packages/chameleon/zpt/template.py", line 307 in render
      File "/home/zope/zope5/lib/python3.7/site-packages/z3c/pt/pagetemplate.py", line 176 in render
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/engine.py", line 365 in __call__
      File "/home/zope/zope5/lib/python3.7/site-packages/zope/pagetemplate/pagetemplate.py", line 135 in pt_render
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/PageTemplate.py", line 85 in pt_render
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/ZopePageTemplate.py", line 343 in pt_render
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/ZopePageTemplate.py", line 279 in _exec
      File "/home/zope/zope5/lib/python3.7/site-packages/Shared/DC/Scripts/Bindings.py", line 370 in _bindAndExec
      File "/home/zope/zope5/lib/python3.7/site-packages/Shared/DC/Scripts/Bindings.py", line 347 in __render_with_namespace__
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/ZRPythonExpr.py", line 82 in call_with_ns
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/Expressions.py", line 111 in render
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/Expressions.py", line 192 in _eval
      File "/home/zope/zope5/lib/python3.7/site-packages/zope/tales/expressions.py", line 250 in __call__
      File "/home/zope/zope5/instance/var/cache/957a703eb61c3ee0b13514b061f8ac18.py", line 129 in __fill_base_container
      File "/home/zope/zope5/instance/var/cache/82bcc8dcd804f6f6013b295a8c667594.py", line 197 in render_base
      File "/home/zope/zope5/instance/var/cache/957a703eb61c3ee0b13514b061f8ac18.py", line 163 in render
      File "/home/zope/zope5/lib/python3.7/site-packages/chameleon/template.py", line 192 in render
      File "/home/zope/zope5/lib/python3.7/site-packages/chameleon/zpt/template.py", line 307 in render
      File "/home/zope/zope5/lib/python3.7/site-packages/z3c/pt/pagetemplate.py", line 176 in render
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/engine.py", line 365 in __call__
      File "/home/zope/zope5/lib/python3.7/site-packages/zope/pagetemplate/pagetemplate.py", line 135 in pt_render
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/PageTemplate.py", line 85 in pt_render
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/ZopePageTemplate.py", line 343 in pt_render
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/ZopePageTemplate.py", line 279 in _exec
      File "/home/zope/zope5/lib/python3.7/site-packages/Shared/DC/Scripts/Bindings.py", line 370 in _bindAndExec
      File "/home/zope/zope5/lib/python3.7/site-packages/Shared/DC/Scripts/Bindings.py", line 347 in __render_with_namespace__
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/ZRPythonExpr.py", line 82 in call_with_ns
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/Expressions.py", line 111 in render
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/Expressions.py", line 192 in _eval
      File "/home/zope/zope5/lib/python3.7/site-packages/zope/tales/expressions.py", line 250 in __call__
      File "/home/zope/zope5/instance/var/cache/957a703eb61c3ee0b13514b061f8ac18.py", line 129 in __fill_base_container
      File "/home/zope/zope5/instance/var/cache/82bcc8dcd804f6f6013b295a8c667594.py", line 197 in render_base
      File "/home/zope/zope5/instance/var/cache/957a703eb61c3ee0b13514b061f8ac18.py", line 163 in render
      File "/home/zope/zope5/lib/python3.7/site-packages/chameleon/template.py", line 192 in render
      File "/home/zope/zope5/lib/python3.7/site-packages/chameleon/zpt/template.py", line 307 in render
      File "/home/zope/zope5/lib/python3.7/site-packages/z3c/pt/pagetemplate.py", line 176 in render
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/engine.py", line 365 in __call__
      File "/home/zope/zope5/lib/python3.7/site-packages/zope/pagetemplate/pagetemplate.py", line 135 in pt_render
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/PageTemplate.py", line 85 in pt_render
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/ZopePageTemplate.py", line 343 in pt_render
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/ZopePageTemplate.py", line 279 in _exec
      File "/home/zope/zope5/lib/python3.7/site-packages/Shared/DC/Scripts/Bindings.py", line 370 in _bindAndExec
      File "/home/zope/zope5/lib/python3.7/site-packages/Shared/DC/Scripts/Bindings.py", line 347 in __render_with_namespace__
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/ZRPythonExpr.py", line 82 in call_with_ns
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/Expressions.py", line 111 in render
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/Expressions.py", line 192 in _eval
      File "/home/zope/zope5/lib/python3.7/site-packages/zope/tales/expressions.py", line 250 in __call__
      File "/home/zope/zope5/instance/var/cache/957a703eb61c3ee0b13514b061f8ac18.py", line 129 in __fill_base_container
      File "/home/zope/zope5/instance/var/cache/82bcc8dcd804f6f6013b295a8c667594.py", line 197 in render_base
      File "/home/zope/zope5/instance/var/cache/957a703eb61c3ee0b13514b061f8ac18.py", line 163 in render
      File "/home/zope/zope5/lib/python3.7/site-packages/chameleon/template.py", line 192 in render
      File "/home/zope/zope5/lib/python3.7/site-packages/chameleon/zpt/template.py", line 307 in render
      File "/home/zope/zope5/lib/python3.7/site-packages/z3c/pt/pagetemplate.py", line 176 in render
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/engine.py", line 365 in __call__
      File "/home/zope/zope5/lib/python3.7/site-packages/zope/pagetemplate/pagetemplate.py", line 135 in pt_render
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/PageTemplate.py", line 85 in pt_render
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/ZopePageTemplate.py", line 343 in pt_render
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/ZopePageTemplate.py", line 279 in _exec
      File "/home/zope/zope5/lib/python3.7/site-packages/Shared/DC/Scripts/Bindings.py", line 370 in _bindAndExec
      File "/home/zope/zope5/lib/python3.7/site-packages/Shared/DC/Scripts/Bindings.py", line 347 in __render_with_namespace__
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/ZRPythonExpr.py", line 82 in call_with_ns
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/Expressions.py", line 111 in render
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/Expressions.py", line 192 in _eval
      File "/home/zope/zope5/lib/python3.7/site-packages/zope/tales/expressions.py", line 250 in __call__
      File "/home/zope/zope5/instance/var/cache/957a703eb61c3ee0b13514b061f8ac18.py", line 129 in __fill_base_container
      File "/home/zope/zope5/instance/var/cache/82bcc8dcd804f6f6013b295a8c667594.py", line 197 in render_base
      File "/home/zope/zope5/instance/var/cache/957a703eb61c3ee0b13514b061f8ac18.py", line 163 in render
      File "/home/zope/zope5/lib/python3.7/site-packages/chameleon/template.py", line 192 in render
      File "/home/zope/zope5/lib/python3.7/site-packages/chameleon/zpt/template.py", line 307 in render
      File "/home/zope/zope5/lib/python3.7/site-packages/z3c/pt/pagetemplate.py", line 176 in render
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/engine.py", line 365 in __call__
      File "/home/zope/zope5/lib/python3.7/site-packages/zope/pagetemplate/pagetemplate.py", line 135 in pt_render
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/PageTemplate.py", line 85 in pt_render
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/ZopePageTemplate.py", line 343 in pt_render
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/ZopePageTemplate.py", line 279 in _exec
      File "/home/zope/zope5/lib/python3.7/site-packages/Shared/DC/Scripts/Bindings.py", line 370 in _bindAndExec
      File "/home/zope/zope5/lib/python3.7/site-packages/Shared/DC/Scripts/Bindings.py", line 347 in __render_with_namespace__
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/ZRPythonExpr.py", line 82 in call_with_ns
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/Expressions.py", line 111 in render
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/Expressions.py", line 192 in _eval
      File "/home/zope/zope5/lib/python3.7/site-packages/zope/tales/expressions.py", line 250 in __call__
      File "/home/zope/zope5/instance/var/cache/957a703eb61c3ee0b13514b061f8ac18.py", line 129 in __fill_base_container
      File "/home/zope/zope5/instance/var/cache/82bcc8dcd804f6f6013b295a8c667594.py", line 197 in render_base
      File "/home/zope/zope5/instance/var/cache/957a703eb61c3ee0b13514b061f8ac18.py", line 163 in render
      File "/home/zope/zope5/lib/python3.7/site-packages/chameleon/template.py", line 192 in render
      File "/home/zope/zope5/lib/python3.7/site-packages/chameleon/zpt/template.py", line 307 in render
      File "/home/zope/zope5/lib/python3.7/site-packages/z3c/pt/pagetemplate.py", line 176 in render
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/engine.py", line 365 in __call__
      File "/home/zope/zope5/lib/python3.7/site-packages/zope/pagetemplate/pagetemplate.py", line 135 in pt_render
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/PageTemplate.py", line 85 in pt_render
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/ZopePageTemplate.py", line 343 in pt_render
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/ZopePageTemplate.py", line 279 in _exec
      File "/home/zope/zope5/lib/python3.7/site-packages/Shared/DC/Scripts/Bindings.py", line 370 in _bindAndExec
      File "/home/zope/zope5/lib/python3.7/site-packages/Shared/DC/Scripts/Bindings.py", line 347 in __render_with_namespace__
      File "/home/zope/zope5/lib/python3.7/site-packages/Products/PageTemplates/ZRPythonExpr.py", line 82 in call_with_ns
    Thread 0x00007fcdcffff700 (most recent call first):
      File "/usr/lib/python3.7/threading.py", line 296 in wait
      File "/home/zope/zope5/lib/python3.7/site-packages/waitress/task.py", line 74 in handler_thread
      File "/usr/lib/python3.7/threading.py", line 865 in run
      File "/usr/lib/python3.7/threading.py", line 917 in _bootstrap_inner
      File "/usr/lib/python3.7/threading.py", line 885 in _bootstrap
    Thread 0x00007fcdd4f8f700 (most recent call first):
      File "/usr/lib/python3.7/threading.py", line 296 in wait
      File "/home/zope/zope5/lib/python3.7/site-packages/waitress/task.py", line 74 in handler_thread
      File "/usr/lib/python3.7/threading.py", line 865 in run
      File "/usr/lib/python3.7/threading.py", line 917 in _bootstrap_inner
      File "/usr/lib/python3.7/threading.py", line 885 in _bootstrap
    Thread 0x00007fcdd5790700 (most recent call first):
      File "/usr/lib/python3.7/threading.py", line 296 in wait
      File "/home/zope/zope5/lib/python3.7/site-packages/waitress/task.py", line 74 in handler_thread
      File "/usr/lib/python3.7/threading.py", line 865 in run
      File "/usr/lib/python3.7/threading.py", line 917 in _bootstrap_inner
      File "/usr/lib/python3.7/threading.py", line 885 in _bootstrap
    Thread 0x00007fcddd4c3740 (most recent call first):
      File "/home/zope/zope5/lib/python3.7/site-packages/waitress/wasyncore.py", line 174 in poll
      File "/home/zope/zope5/lib/python3.7/site-packages/waitress/wasyncore.py", line 247 in loop
      File "/home/zope/zope5/lib/python3.7/site-packages/waitress/server.py", line 165 in run
      File "/home/zope/zope5/lib/python3.7/site-packages/waitress/__init__.py", line 18 in serve
      File "/home/zope/zope5/lib/python3.7/site-packages/waitress/__init__.py", line 22 in serve_paste
      File "/home/zope/zope5/lib/python3.7/site-packages/paste/deploy/util.py", line 55 in fix_call
      File "/home/zope/zope5/lib/python3.7/site-packages/paste/deploy/loadwsgi.py", line 195 in server_wrapper
      File "/home/zope/zope5/lib/python3.7/site-packages/Zope2/Startup/serve.py", line 203 in serve
      File "/home/zope/zope5/lib/python3.7/site-packages/Zope2/Startup/serve.py", line 217 in run
      File "/home/zope/zope5/lib/python3.7/site-packages/Zope2/Startup/serve.py", line 251 in main
      File "bin/runwsgi", line 8 in <module>
    ^C
    [1]+  Aborted                 bin/runwsgi -v instance/etc/zope.ini  (wd: ~/zope5)
    (wd now: ~/zope5/instance/var/cache)

I have emptied the Chameleon cache and the result is the same

Here is the code I made for my tests:

This one works:
My macro :

<metal:x define-macro="base">
<!doctype html>
< html lang="fr">
< head>
< meta charset="UTF-8" />
< meta name="viewport" content="width=device-width, initial-scale=1.0" />

< /head>
< body class="bg-black bg-cover bg-no-repeat bg-top overflow-hidden" tal:define="T python:'toto'">
< div class="w-screen h-screen overflow-x-hidden overflow-y-auto">
< tal:x metal:define-slot="base-container"><tal:x content="T"></tal:x></tal:x>
< /div>
< /body>
< /html>
< /metal:x>

my page calling my macro and using the variable T defined in the macro :

<metal:x use-macro="context/base.html/macros/base">
<metal:fill fill-slot="base-container">
<tal:x content="T"></tal:x>< br>
appel direct dans la page template utilisant la macro
</metal:fill>
</metal:x>

and below the code that crashes my instance:

<metal:x use-macro="context/base.html/macros/base">
<metal:fill fill-slot="base-container">
<tal:x content="structure context/pushComponent.html"></tal:x>< br>
Injection d'une page template "pushComponent.html"
</metal:fill>
</metal:x>

With this code in the component :

<tal:x content="T"></tal:x>< br>
Appel dans un composant

I will refer this problem to the author of Chameleon but if you have any ideas.
Thanks

You have an infinite recursion. In order to figure out what's happening, you need to get a traceback.

Oh, sorry, I just saw the error.
I called the file itself in itself.

But after correcting my code (fortunately, it no longer crashes my Zope5 instance), I still cannot recover my T variable defined in the macro, in a template page injected into a page using the macro.
An idea?

Here is the trace :

KeyError

'T'

  • Expression: "T"
  • Filename: /TEST/pushComponent.html
  • Location: (line 1: col 16)
  • Expression: "python:'toto'"
  • Filename: /TEST/base.html
  • Location: (line 9: col 82)
  • Expression: "context/base.html/macros/base"
  • Filename: /TEST/pushBaseMacro.html
  • Location: (line 2: col 20)
  • Arguments: template: here: context: container: nothing: None options: {'args': ()} root: request: modules: traverse_subpath: user: default: repeat: loop: {} target_language: None translate: .translate at 0x7f79142bb6a8> attrs: {}

Traceback (innermost last):

  • Module ZPublisher.WSGIPublisher, line 167, in transaction_pubevents
  • Module ZPublisher.WSGIPublisher, line 376, in publish_module
  • Module ZPublisher.WSGIPublisher, line 279, in publish
  • Module ZPublisher.mapply, line 85, in mapply
  • Module ZPublisher.WSGIPublisher, line 68, in call_object
  • Module Shared.DC.Scripts.Bindings, line 333, in call
  • Module Shared.DC.Scripts.Bindings, line 370, in _bindAndExec
  • Module Products.PageTemplates.ZopePageTemplate, line 279, in _exec
  • Module Products.PageTemplates.ZopePageTemplate, line 343, in pt_render
  • Module Products.PageTemplates.PageTemplate, line 85, in pt_render
  • Module zope.pagetemplate.pagetemplate, line 135, in pt_render
  • Module Products.PageTemplates.engine, line 365, in call
  • Module z3c.pt.pagetemplate, line 176, in render
  • Module chameleon.zpt.template, line 307, in render
  • Module chameleon.template, line 192, in render
  • Module 8e4e3b75c5a1aa8a18adafeca76f0112, line 163, in render
  • Module 82bcc8dcd804f6f6013b295a8c667594, line 197, in render_base
  • Module 8e4e3b75c5a1aa8a18adafeca76f0112, line 129, in __fill_base_container
  • Module zope.tales.expressions, line 250, in call
  • Module Products.PageTemplates.Expressions, line 192, in _eval
  • Module Products.PageTemplates.Expressions, line 111, in render
  • Module Products.PageTemplates.ZRPythonExpr, line 82, in call_with_ns
  • Module Shared.DC.Scripts.Bindings, line 347, in render_with_namespace
  • Module Shared.DC.Scripts.Bindings, line 370, in _bindAndExec
  • Module Products.PageTemplates.ZopePageTemplate, line 279, in _exec
  • Module Products.PageTemplates.ZopePageTemplate, line 343, in pt_render
  • Module Products.PageTemplates.PageTemplate, line 85, in pt_render
  • Module zope.pagetemplate.pagetemplate, line 135, in pt_render
  • Module Products.PageTemplates.engine, line 365, in call
  • Module z3c.pt.pagetemplate, line 176, in render
  • Module chameleon.zpt.template, line 307, in render
  • Module chameleon.template, line 214, in render
  • Module chameleon.utils, line 75, in raise_with_traceback
  • Module chameleon.template, line 192, in render
  • Module 2415c1d6d698011e31c08af9a5487baa, line 110, in render
  • Module zope.tales.expressions, line 250, in call
  • Module Products.PageTemplates.Expressions, line 184, in _eval
  • Module zope.tales.expressions, line 143, in _eval
  • Module Products.PageTemplates.engine, line 176, in getitem

We nned (again) your precise code.

With "normal" macros, you rarely need the global definition. It is there mainly to have common definitions encapsulated in a macro. If your case is "normal", you may try to omit the global (even though modern chameleon versions should handle global variables correctly).

the precise code is the one put in my post Macros template push variable
I did delete the "global" directive but nothing helps.
I think Chameleon does not propagate macro variables in "include".

After checking, I did the same test on a Zope2 (2.12) instance and have the same behavior.
Too bad that the macros do not globally distribute the variables defined in them.

As I said earlier, variables defined in a template are not passed (automatically) to calls. This applies to any calls, even calls to other templates. You are calling your "component" templates.

As you have found out, this is not a chameleon only behavior. It applies to all template engines.

You have 2 options:

  • pass the value explicitly to the the call
  • use request to store the value

Plone Foundation Code of Conduct