Closed petschki closed 6 months ago
Peter Mathis wrote at 2022-12-7 06:46 -0800:
... Instead of usually place unescaped HTML inside templates like
I tried the Chameleon"short-hand text insertion" for unescaped HTML like documented here https://chameleon.readthedocs.io/en/latest/ <p>${structure:view/some_formatted_html}</p>
What I expect to happen:
The formatted HTML string returned from the view should be placed unescaped inside the template.
By default, Zope
's PageTemplate
s use zope.tales
not chameleon.tales
as TALES expression engine.
zope.tales
does not know about the "new types"
of chameleon.tales
(described by
"https://chameleon.readthedocs.io/en/latest/reference.html#new-features"),
among them the structure:
type.
You can define templates using chamelon.tales
by overriding their
pt_getEngine
to return a TALES engine defined in
Products.PageTemplates.expression
.
Note that templates using different TALES engines are not fully compatible: You cannot use a macro defined by a template with a different TALES engine.
If those "new types" are really important, they might get
supported by zope.tales
.
Moved the issue because it is effectively a feature request for zope.tales
Is there really a structure
type in chameleon
?
@petschki What happens when using <p>${structure view/some_formatted_html}</p>
(without the colon)? (Or maybe <p>${structure view.some_formatted_html()}</p>
as chameleon defaults to the python
type.)
Moved the issue because it is effectively a feature request for
zope.tales
Sorry @dataflake I have been wrong: zope.tales
cannot implement the structure
"type" (not without a strong chameleon
dependency).
structure
is not a "genuine" type. Typical types control the computation of the value; in contrast, structure
does not change the value computation but instead tags it with a command to the template engine not to quote the value when it is incorporated into the template. chameleon
has put structure
which logically belongs to template world into the expression world. In order for zope.tales
to implement this, it must know chameleon
implementation details (specifically how to wrap the value to tell the chameleon
template engine not to quote).
If this should be implemented, the Zope/chameleon integration point (i.e. Products.PageTemplates
, part of Zope) is the correct place (as it depends both on zope.tales
and chameleon
). Therefore, I will move the issue back. Sorry again!
Is there really a
structure
type inchameleon
?
@icemac It is, see e.g. "https://chameleon.readthedocs.io/en/latest/reference.html#types".
The list of "types" contains further elements currently not supported by the Zope
integration, e.g. import
(supported in Zope
by the predefined variable modules
) and load
.
PROBLEM REPORT
What I did:
Instead of usually place unescaped HTML inside templates like
I tried the Chameleon"short-hand text insertion" for unescaped HTML like documented here https://chameleon.readthedocs.io/en/latest/
What I expect to happen:
The formatted HTML string returned from the view should be placed unescaped inside the template.
What actually happened:
A traceback:
What version of Python and Zope/Addons I am using:
Python: 3.10.7 Zope: 5.7 Plone: 6.0.0rc2 MacOS: Ventura 13.0.1