How to deliver static html with plone.app.theming

187 Views Asked by At

I use Diazo to deploy the static html-file 'ticker.html' on a certain url. That page uses nothing at all from the content.

This is the rules.xml:

<rules xmlns="http://namespaces.plone.org/diazo"
       xmlns:css="http://namespaces.plone.org/diazo/css"
       xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <rules if-path="/Plone/ticker/ /ticker/">
    <theme href="ticker.html" />
  </rules>

  <rules css:if-content="#visual-portal-wrapper" if-not-path="/Plone/ticker/ /ticker/">
    <theme href="index.html" />    
    The rest of the theme...
  </rules>
</rules>

It works fine and the html is correct but the return-code of http://localhost:8080/Plone/ticker is 404. Only if I create some dummy content in Plone at this location I get a 200. The returned is also slightly changed: When there is a dummy content Diazo adds a base-tag to the header:

<base href="http://localhost:8080/Plone/ticker/" />

How can I tell Diazo to completely ignore the content and return a 200 even when there is no dummy-content?

In case you are wondering: I use Diazo for this because plone.app.themeing allows to modify the static page through the web.

2

There are 2 best solutions below

1
SteveM On BEST ANSWER

The plone.app.theming transformation is the last step in the delivery pipeline. The content has already been summoned from Plone so that it can be combined with the theme. So, it's not the appropriate place to do this.

Instead, do this with the rewrite rules of your reverse proxy. Have the proxy fetch your ticker whenever it receives a request for the target URL. You'll also save a lot of CPU cycles in the process, since you'll avoid the whole trip through Zope/Plone's machinery.

0
widerin On

I had a similar usecase where i want to server some js-partials through Zope to AngularJS. They are text/html so they got transformed through plone.app.theming. After a deep look into plone.app.theming i overloaded the ThemeTranform adapter with a subclassed one in a new file transforms.py as shown below:

# -*- coding: utf-8 -*-
from plone.app.theming import transform
from your.theme.interfaces import IYourThemeLayer
from zope.component import adapter
from zope.interface import Interface


@adapter(Interface, IYourThemeLayer
class ThemeTransform(transform.ThemeTransform):

    def parseTree(self, result):

        # Prevent diazo from adding doctype and html head to every
        # html file. Exclude all partial resources from theme transforms
        if '/++resource++your.theme.js-partials/' in self.request.getURL():
            return None

        return super(ThemeTransform, self).parseTree(result)

... and register in zcml to the same name as the default ThemeTransform adapter using:

<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:zcml="http://namespaces.zope.org/zcml"
    i18n_domain="your.theme">

    <!-- Override plone.app.theming adapter -->
    <adapter
        name="plone.app.theming.transform"
        factory=".transform.ThemeTransform"
        zcml:condition="installed plone.app.theming"
        />

</configure>

May be related to this issue: https://dev.plone.org/ticket/13139