Skip to content

Support Chameleon attribute expressions.#213

Open
thet wants to merge 3 commits into
masterfrom
thet/fix-chameleon-expressions
Open

Support Chameleon attribute expressions.#213
thet wants to merge 3 commits into
masterfrom
thet/fix-chameleon-expressions

Conversation

@thet
Copy link
Copy Markdown
Member

@thet thet commented May 8, 2026

Fix incorrect splitting of Chameleon attribute expressions which led to broken code.

This HTML <input type="text" ${python: "required" if view.required else ""} /> leads now correctly to:

<input type="text"
       ${python: "required" if view.required else ""}
/>

Note: without this fix it is:

<input ""}=""
        "required"=""
        ${python:=""
        else=""
        if=""
        type="text"
        view.required=""
/>

Note 2: This vix is vibe coded. The previous two PRs are not.

@thet thet requested a review from ale-rt May 8, 2026 23:54
Fix incorrect splitting of Chameleon attribute expressions which led to
broken code.

This HTML `<input type="text" ${python: "required" if view.required else ""} />`
leads now correctly to:

```html
<input type="text"
       ${python: "required" if view.required else ""}
/>
```
@thet thet force-pushed the thet/fix-chameleon-expressions branch from efd1ca0 to 5c67c34 Compare May 8, 2026 23:56
@coveralls
Copy link
Copy Markdown

coveralls commented May 8, 2026

Coverage Status

Coverage is 96.753%thet/fix-chameleon-expressions into master. No base build found for master.

Copy link
Copy Markdown
Member

@ale-rt ale-rt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is broken XML and I think it is not allowed by Chameleon.

It seems to me that you should replace:

${python: "required" if view.required else ""}

with:

required="${python: "required" if view.required else ""}

Am I wrong?

@gforcada
Copy link
Copy Markdown
Member

@ale-rt since HTML5 it is no longer strictly speaking XML anymore 🙃

https://stackoverflow.com/questions/5558502/is-html5-valid-xml and plenty of other examples

@ale-rt
Copy link
Copy Markdown
Member

ale-rt commented May 15, 2026

@ale-rt since HTML5 it is no longer strictly speaking XML anymore 🙃

Thanks for the heads up, but this HTML is not relevant here.
You can even use chameleon to render a markdown document and this is even tested in zpretty:

The point is that chameleon wants a proper XML snippet.
Try putting this in the test_rendering template and load the page.

<h1 ${python: "hidden" if False else ""}>Plone User Interface elements test page</h1>

It breaks with:

2026-05-15 12:42:31,870 ERROR   [Zope.SiteErrorLog:35][waitress-2] PTRuntimeError: http://0.0.0.0:9000/Plone/test_rendering
Traceback (innermost last):
  Module ZPublisher.WSGIPublisher, line 181, in transaction_pubevents
  Module ZPublisher.WSGIPublisher, line 390, in publish_module
  Module ZPublisher.WSGIPublisher, line 284, in publish
  Module ZPublisher.mapply, line 98, in mapply
  Module ZPublisher.WSGIPublisher, line 68, in call_object
  Module Products.CMFPlone.browser.test_rendering, line 11, in __call__
  Module Products.Five.browser.pagetemplatefile, line 127, in __call__
  Module Products.Five.browser.pagetemplatefile, line 59, in __call__
  Module zope.pagetemplate.pagetemplate, line 130, in pt_render
   - Warning: Compilation failed
   - Warning: chameleon.exc.ParseError: Unexpected end tag.

 - String:     "</h1>"
 - Filename:   /home/ale/Code/plone/projects/plonex/.venv/lib/python3.13/site-packages/Products/CMFPlone/browser/templates/test_rendering.pt
 - Location:   (line 25: col 83)
 - Source:     ... er Interface elements test page</h1>

The proper syntax is:

<h1 hidden="${python: 'hidden' if False else None}">Plone User Interface elements test page</h1>

I would say this PR is invalid.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants