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

Template problem with nested curly braces and chameleon expressions. #925

Closed
mauritsvanrees opened this issue Oct 30, 2020 · 9 comments
Closed
Labels

Comments

@mauritsvanrees
Copy link
Member

This is with Zope 4.5.1.
See community.plone.org where Marcel Liebischer reports this. I can confirm it, and see the same in the current core Plone 5.2 development buildout, which I think has some newer versions for template related packages.

Let me copy the original report here:


I ran into another problem with page templates and Plone 5.2.2.

It seems there are problems with nested curly braces and chameleon expressions. This could easily happen if you try to build a data-attribute with some JSON data in a page template.

Steps to reproduce:

<span data-test='{"foo": "${view/somemethod}"}'/>

-> does not work. Throws "zope.location.interfaces.LocationError .. (view object, 'somemethod)'"

<span data-test='"foo": "${view/somemethod}"'/>

-> works fine (but it's not valid JSON)

<span data-test='{"foo": "${python: view.somemethod()}"'/>

-> works fine

The issues does not exist in Plone 5.2.0.

@dataflake
Copy link
Member

It would help if someone who knows Plone could help get past all those parts that have to do with Plone and present a test case with Zope only.

@mauritsvanrees
Copy link
Member Author

Simply create a Zope instance, start it up, in the ZMI add a Page Template (I chose id test). Edit to have this in the body:

  1. <span data-test='{"foo": "${template/id}"}'/>: fails with: zExceptions.NotFound: id}" - Expression: "template/id}"" - Filename: /test - Location: (line 17: col 28) - Arguments: template: here: context: container: nothing: None options: {'args': ()} root: request: modules: traverse_subpath: [] user: default: repeat: loop: {} target_language: None translate: .translate at 0x1085b3940> attrs: {'data-test': '{"foo": "${template/id}"}'}

  2. <span data-test='"foo": "${template/id}"'/>: works (but is not valid JSON, which is what the original poster wanted). Result: <span data-test='"foo": "test"'/>.

  3. <span data-test='{"foo": "${python: template.id}"}'/>: works fine. Result: <span data-test='{"foo": "test"}'/>.

The first one shows that path substitution in a string with extra curly braces fails.

The second one shows that path substitution in a normal string without curly braces works.

The third one shows that python substitution in a sting with curly braces works.

@dataflake
Copy link
Member

Do you have a link to a file that tells me what the versions for Plone 5.2.0 and 5.2.2 are so I can find the actual differences?

@d-maurer
Copy link
Contributor

d-maurer commented Oct 30, 2020 via email

@d-maurer
Copy link
Contributor

d-maurer commented Oct 30, 2020 via email

@mauritsvanrees
Copy link
Member Author

Do you have a link to a file that tells me what the versions for Plone 5.2.0 and 5.2.2 are so I can find the actual differences?

Plone 5.2.0 and 5.2.1 will behave the same here, I expect, so let's take that one as the baseline.

The relevant difference is easy (but big):

  • 5.2.1 uses Zope 4.1.3
  • 5.2.2 uses Zope 4.5.1, including the template engine changes from 4.4 and the related fixes from 4.5.

@d-maurer
Copy link
Contributor

d-maurer commented Oct 30, 2020 via email

@d-maurer
Copy link
Contributor

d-maurer commented Nov 2, 2020

I have implemented the approach sketched in the previous comment in #927

@mauritsvanrees
Copy link
Member Author

Yes, the merged PR works. The previously failing code from my first example is now properly handled without error.
Thank you!

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

No branches or pull requests

3 participants