Strange difference in ViewPageTemplateFile in Plone 5

I encounter a strange difference between Plone 4 and Plone 5 regarding ViewPageTemplateFile usage.

A browser view instantiates a custom ViewPageTemplateFile and returns the rendered result.

  def __call__(self, *args, **kw):

        from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
        template = ViewPageTemplateFile('')
        return template.pt_render(dict(context=self.context, request=self.request))

This works in Plone 4.3 but fails in Plone 5...any incompatibility issue I am missing here?

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 xmldirector.plonecore.browser.connector, line 288, in __call__
  Module zope.pagetemplate.pagetemplate, line 132, in pt_render
  Module, line 93, in __call__
  Module, 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, line 204, in render
  Module, line 971, in render_master
  Module, line 165, in bodyClass
AttributeError: 'str' object has no attribute 'getId'

 - Expression: "python:plone_layout.bodyClass(template, view)"
 - Filename:   ... egg/Products/CMFPlone/browser/templates/
 - Location:   (line 45: col 28)
 - Source:     ... e="isRTL portal_state/is_rtl;
 - Arguments:  repeat: {...} (0)
               context: <ImplicitAcquisitionWrapper file at 0x7f1e2641f780>
               default: <object - at 0x7f1e3a0e7c20>
               request: <instance - at 0x7f1e25ea65f0>
               wrapped_repeat: <SafeMapping - at 0x7f1e24041f18>
               loop: {...} (0)
               nothing: <NoneType - at 0x7b4050>
               translate: <function translate at 0x7f1e223ceb18>
               target_language: <NoneType - at 0x7b4050>

This looks like an error on main_template rather than your custom template. least there is a difference between:

class MyView(BrowserView):
   template = ViewPageTemplateFile(....)

  def __call__(self):
      return self.template() # BoundPageTemplateFile


class MyView(BrowserView):
  def __call__(self):
      template = ViewPageTemplateFile(....)
      return template.pt_render()

The bodyClasses() implementation seems to assume the template is always bound using the variant #1.


Workaround or fix!?


This bug in

is still open and breaking Plone 5.0.5 with various add-ons.

The Travis information for this PR for Plone 5.0 is no longer available.