ExpressionError: Not a valid path-expression after embed form in template

Hi, I embed form in template:

<div id="bg-form-contact">
<div tal:content="structure contact-1/@@embedded" />
</div>

path is valid I can open it in browser /contact-1/@@embedded

but I receive:

Traceback (innermost last):

Module ZPublisher.Publish, line 138, in publish
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 48, in call_object
Module Products.Five.browser.metaconfigure, line 485, in call
Module Products.Five.browser.pagetemplatefile, line 125, in call
Module Products.Five.browser.pagetemplatefile, line 59, in call
Module zope.pagetemplate.pagetemplate, line 137, in pt_render
Module five.pt.engine, line 98, in call
Module z3c.pt.pagetemplate, line 163, in render
Module chameleon.zpt.template, line 261, in render
Module chameleon.template, line 191, in render
Module chameleon.template, line 171, in render
Module 2f6a59085031d1ea5b14f54b01b554bf.py, line 103, in render
ExpressionError: Not a valid path-expression.

  • String: "contact-1/@@embedded"
  • Filename: /home/pablo_rosales/Plone/zinstance/src/ploneconf.theme/src/ploneconf/theme/browser/templates/contact-form.pt
  • Location: (line 2: col 28)

please help me. Thanks.

I can image that the -1 causes the problem problem..don't ask me about the validity of path expressions here...but a workaround would be:

 div tal:content="structure python: context['contact-1'].restrictedTraverse('@@embedded')()" />

-aj

1 Like

I have some doubts about context here. That you can call /contact-1/@@embedded in a browser doesn't mean or prove that the context in/on which your template will be called can also find contact-1/@@embedded. The 'location error' is indicative that a path cannot be traversed.

I validated and confirmed the issue with contact-1 vs a non-offending contact_1 object ID.

-aj

@zopyx Andreas, I wasn't doubting your suggested fix, but the general use of context and testing in OP's message :wink:

Good to know that this indeed a problem in path expressions, especially when Plone's IIDNormalizer add's -1 when it detects duplicated id's... :frowning:

In fact the original code by @bespider is not correct since the this was supposed likely to be

<div tal:content="structure context/contact-1/@@embedded"/>

I have not seen a former tal:define for contact-1.

So the primary code appears wrong but perhaps also the syntax check for path expressions...don't know..I am not a language lawyer.