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

Mosaic tile not interpreting html tags in script tag #424

Open
yleclanche opened this issue Sep 11, 2018 · 4 comments
Open

Mosaic tile not interpreting html tags in script tag #424

yleclanche opened this issue Sep 11, 2018 · 4 comments

Comments

@yleclanche
Copy link

I'm using mustache template in a mosaic tile.
When the page is rendering, the html content of the mustache template is displayed as raw html instead of being interpreted.

Any idea why and how to fix this ?

Thanks.

@fredvd
Copy link
Sponsor Member

fredvd commented Sep 14, 2018

AFAIK the tile are rendered using ZPT (zope page templates, not Mustache). Or maybe you mean something different. Can you post the template here?

@yleclanche
Copy link
Author

Sorry, I was not very explicit.
I use ZPT for the mosaic tile. But inside my template code, I have some mustache code too.

The issue was in plone.app.blocks-4.1.1-py2.7.egg/plone/app/blocks/utils.py in the resolve function.
The content of the tiles are sent to the elementtree html parser. I guess html tags in a script tags is not valid so tags are escaped.

The solution is a bit ugly. I replaced all my <script type="text/x-mustache-template"> tags to <code> tags in my template. Then I patched the resolve function tu replace <code> tags to <script> tags after the html parser did his work.

def resolve(url, resolved=None):
    """Resolve the given URL to an lxml tree.
    """
    if resolved is None:
        resolved = resolveResource(url)
    if not resolved.strip():
        return None
    try:
        if isinstance(resolved, unicode):
            resolved = resolved.encode('utf-8')
        html_parser = html.HTMLParser(encoding='utf-8',)
        # patch starts here
        htmltree = html.fromstring(resolved, parser=html_parser).getroottree()
        for tag in htmltree.iterfind('.//code[@type="text/x-mustache-template"]'):
            tag.tag = "script"
        # patch ends here
        return htmltree

    except etree.XMLSyntaxError as e:
        logger.error('%s: %s' % (repr(e), url))
        return None

I close this issue because I'm not sure it's a bug.

@hvelarde
Copy link
Member

hvelarde commented Sep 14, 2018

@yleclanche what you're trying to do seems valid to me; we have something similar using Mustache in Zope page templates in collective.upload.

so, it should work here also.

@yleclanche
Copy link
Author

The mustache code works in a standard browser view, just not within a custom Mosaic tile template.

krissik pushed a commit that referenced this issue Mar 11, 2024
Fix several problems with the Indonesian language [7.x]
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

No branches or pull requests

3 participants