Main_template macro in p.a.z3cform.templates.layout.pt

While looking for an example for @pigeonflight on how we use example.trajectory I stumbled on the traceback below when navigating to the article edit form. I was able to get my edit form to work by changing

      metal:use-macro="here/main_template/macros/master"

to

      metal:use-macro="here/@@main_template/macros/master"

(which I remember seeing in one of the training.plone.org courses but am unable to find right now)

What makes this change work?

2020-08-20 16:35:06 ERROR Zope.SiteErrorLog 1597934106.110.802185519336 http://192.168.0.245:8585/mdb/articles/00014/@@edit
Traceback (innermost last):
  Module ZPublisher.Publish, line 138, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 48, in call_object
  Module plone.z3cform.layout, line 64, in __call__
  Module plone.z3cform.layout, line 80, in render
  Module Products.Five.browser.pagetemplatefile, line 125, in __call__
  Module Products.Five.browser.pagetemplatefile, line 59, in __call__
  Module zope.pagetemplate.pagetemplate, line 137, in pt_render
  Module five.pt.engine, line 98, in __call__
  Module z3c.pt.pagetemplate, line 163, in render
  Module chameleon.zpt.template, line 261, in render
  Module chameleon.template, line 191, in render
  Module chameleon.template, line 171, in render
  Module 411de03efebd9251e8460a3c34b3faf6.py, line 232, in render
  Module five.pt.expressions, line 154, in __call__
  Module five.pt.expressions, line 126, in traverse
  Module zope.traversing.adapters, line 142, in traversePathElement
   - __traceback_info__: (<example.trajectory.article.trajectory.ArticleWrapper object at 0x7ff6fd2a61d0>, 'main_template')
  Module zope.traversing.adapters, line 56, in traverse
   - __traceback_info__: (<example.trajectory.article.trajectory.ArticleWrapper object at 0x7ff6fd2a61d0>, 'main_template', ('macros', 'master'))
LocationError: (<example.trajectory.article.trajectory.ArticleWrapper object at 0x7ff6fd2a61d0>, 'main_template')

 - Expression: "here/main_template/macros/master"
 - Filename:   ... m-3.0.10-py2.7.egg/plone/app/z3cform/templates/layout.pt
 - Location:   (line 6: col 23)
 - Source:     metal:use-macro="here/main_template/macros/master"
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 - Arguments:  repeat: {...} (0)
               template: <ViewPageTemplateFile - at 0x7ff6ffb785d0>
               views: <ViewMapper - at 0x7ff6fff0f190>
               modules: <instance - at 0x7ff70af68830>
               args: <tuple - at 0x7ff7136b7050>
               here: <ImplicitAcquisitionWrapper 00014 at 0x7ff70384e730>
               user: <ImplicitAcquisitionWrapper - at 0x7ff70384db40>
               nothing: <NoneType - at 0x8f5320>
               container: <ImplicitAcquisitionWrapper 00014 at 0x7ff70384e730>
               request: <instance - at 0x7ff703a8b170>
               wrapped_repeat: <SafeMapping - at 0x7ff700144af8>
               traverse_subpath: <list - at 0x7ff6fcf2d3f8>
               default: <object - at 0x7ff7135d5530>
               loop: {...} (0)
               context: <ImplicitAcquisitionWrapper 00014 at 0x7ff70384e730>
               view: <EditView edit at 0x7ff6fd36e190>
               translate: <function translate at 0x7ff6fcd95b18>
               root: <ImplicitAcquisitionWrapper Zope at 0x7ff7039c9730>
               options: {...} (0)
               target_language: <NoneType - at 0x8f5320>

Which version of Plone and Zope are you using?

I have seen a similar problem with the following cause: newer Zope versions fully honor a template's specification regarding the TALES implementation; z3c.form templates use a TALES path expression which is not Zope aware (because z2c.form was originally developed for Zope 3, not Zope [2]). This let some path expressions fail in templates derived from z3c.form templates which usually work perfectly. Plone 5.2.2 is supposed to have a workaround for this.

Thanks @dieter

Version Overview

Plone 5.1.6 (5116)
CMF 2.2.13
Zope 2.13.29
Python 2.7.12 (default, Nov 12 2018, 14:36:49) [GCC 5.4.0 20160609]
PIL 5.2.0 (Pillow)

plone.app.z3cform is version 3.0.10

views.py contains this interesting snippet:

layout_factory = plone.z3cform.templates.ZopeTwoFormTemplateFactory(
    path('layout.pt'),
    form=plone.z3cform.interfaces.IFormWrapper,
    request=plone.app.z3cform.interfaces.IPloneFormLayer)

Which, I guess, is the cause that I can not override the template using z3c.jbot

You might face a problem similar to the one I mentioned even though the versions you are using are sufficiently old to not cause the exact problem (Zope fully honoring the TALES implementation called for by the template was introduced in Zope 4.4).

The 'goggles' or glasses @@ will afaik prevent acquisition from happening in that expression.

So @@myview name will only find the ZCA registered named multi-adapter with myview on request and context 'here'.

With 'here/blabla' as a tales expression, blabla could be an object in the parent of 'here', or an attribute on the portal root (Acqusition).

Maybe this has changed in recent Zope version and I am not sure what the exact ordering between zca and good old Acquisition is nowadays.

Given that the plone.app.z3cform form.pt and layout.pt templates are not overridable with jbot anyway but require a custom formwrapper to do so, would it not be correct to explicitely add the @@main_template stanza there and prevent acquisition by default?

Plone Foundation Code of Conduct