Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chameleon short-hand text insertion ${structure: ...} throws exception #1077

Closed
petschki opened this issue Dec 7, 2022 · 5 comments · Fixed by #1199
Closed

Chameleon short-hand text insertion ${structure: ...} throws exception #1077

petschki opened this issue Dec 7, 2022 · 5 comments · Fixed by #1199

Comments

@petschki
Copy link

petschki commented Dec 7, 2022

PROBLEM REPORT

What I did:

Instead of usually place unescaped HTML inside templates like

<span tal:replace="structure view/some_formatted_html" />

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.

What actually happened:

A traceback:

Traceback (innermost last):
  Module ZPublisher.WSGIPublisher, line 167, in transaction_pubevents
  Module ZPublisher.WSGIPublisher, line 376, in publish_module
  Module ZPublisher.WSGIPublisher, line 271, in publish
  Module ZPublisher.mapply, line 85, in mapply
  Module ZPublisher.WSGIPublisher, line 68, in call_object
  Module zope.browserpage.simpleviewclass, line 41, in __call__
  Module Products.Five.browser.pagetemplatefile, line 126, in __call__
  Module Products.Five.browser.pagetemplatefile, line 58, in __call__
  Module zope.pagetemplate.pagetemplate, line 129, in pt_render
   - Warning: Compilation failed
   - Warning: builtins.LookupError: Unknown expression type: 'structure'.
zope.pagetemplate.pagetemplate.PTRuntimeError: ['Compilation failed', "builtins.LookupError: Unknown expression type: 'structure'."]

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

@petschki petschki added the bug label Dec 7, 2022
@d-maurer
Copy link
Contributor

d-maurer commented Dec 7, 2022 via email

@dataflake dataflake transferred this issue from zopefoundation/Zope Dec 15, 2022
@dataflake
Copy link
Member

Moved the issue because it is effectively a feature request for zope.tales

@dataflake dataflake added enhancement and removed bug labels Dec 15, 2022
@icemac
Copy link
Member

icemac commented Dec 16, 2022

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.)

@d-maurer
Copy link
Contributor

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!

@d-maurer
Copy link
Contributor

Is there really a structure type in chameleon?

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants