I'm a Plone user and I've been using tal macros from Products.Five.browser.pagetemplatefile.ViewPageTemplateFile for quite a while and created a library of existing macros and templates.
I started using chameleon page templates through grokcore.chameleon 1.0.3, and would like to keep using them within the existing framework. I.E. I want to be able to import tal macros and then fill out macro slots using chameleon.
So far I tried several ways of importing existing macro but none of them worked. 'Load' keyword isn't enabled even though Chameleon 2.14 is installed[1].
I've been looking for a compatibility layer, but all I've found so far is z3c.pt, which purpose is to speed up .pt page rendering and not provide compatibility layer.[2]
Are there any packages that activate tal macro and then insert information from a Chameleon page template? As a workaround I can render tal template, render chameleon template and then do string substitution, but there's got to be someone who solved this problem in a more elegant way.
[1] how to use macros with pyramid / ZPT (Chameleon)
[2] https://pypi.python.org/pypi/z3c.pt
Update As a workaround I create a function that generates an intermediate page, which accepts html generated by chameleon page template.
common.py
from zope.publisher.browser import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
def insert_into_master(html, view):
class View(BrowserView):
def __call__(self):
self.data = html
return ViewPageTemplateFile('pt/master_holder.pt')(self)
rendered = View(view.context, view.request)
return rendered()
pt/master_holder.pt
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
metal:use-macro="here/main_template/macros/master"
i18n:domain="Plone"
xml:lang="en"
lang="en">
<div
metal:fill-slot="main"
tal:content="structure:view/data"
/>
</html>
any client view that uses chameleon
from five import grok
from zope.interface import Interface
from grokcore.chameleon.components import ChameleonPageTemplate
from common import insert_into_master
class MyView(grok.View):
grok.context(Interface)
grok.require('zope2.View')
grok.name('myview')
def render(self):
view = ChameleonPageTemplate('<div>Hello, world!</div>')
return insert_into_master(view.render(self), self)