Diazo using portal url in path in index.html

In my theme, I want to have

<html manifest="{$portal_url}/cache.manifest">

Is this somehow possible in the index.html file ?

If not: maybe it can be done with a diazo rule ?

PS: The reason I am not hardcoding it is because I want to use the same theme for several lineage subsiites

AFAIK, it's not possible in the index.html file. But you can use Diazo:

Define the param portal_url in your manifest.cfg:

[theme]
title = Your Theme
description = A Theme.
preview = preview.png
doctype = <!DOCTYPE html>

[theme:parameters]
portal_url = portal_state/portal_url

You should add a default for portal_url - acting as a fallback - to you root rules.xml file (you never know what users do with the advanced theme settings), so your theme will still work even if the param is removed from the theme:parameters section:

<?xml version="1.0" encoding="UTF-8"?>
<rules xmlns="http://namespaces.plone.org/diazo"
    xmlns:css="http://namespaces.plone.org/diazo/css"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xi="http://www.w3.org/2001/XInclude">

  <!-- The empty param defined here will be overridden by your manifest.cfg. -->
  <xsl:param name="portal_url"></xsl:param>

  <!-- Now add your rules ... -->
</rules>

To adjust the html tag in your theme you can use the following rules:

<!-- Copy all attributes from Plone. -->
<copy attributes="*" css:theme="html" css:content="html" />
<!-- Set cache manifest. -->
<before theme-children="html">
  <xsl:attribute name="manifest"><xsl:value-of select="$portal_url" />/cache.manifest</xsl:attribute>
</before>

I tested this in one of my themes and the output was:

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" manifest="http://localhost:8080/Plone/cache.manifest" xml:lang="en">

I don't know how the expression portal_state/portal_url behaves with lineage sites.

4 Likes

thanks for the detailed explanation thomas.

this is related and might be interesting for others too:
how would i use the portal_url in a replace statement that inserts the result of a view?

currently i do use an absolute url (which is not working when accessing the portal via zope eg localhost:8080/Plone)

<replace css:content='#css-id' css:theme='#css-id' href="/@@my-view" />

thanks

That is different. You can use the portal_url to adjust the rendered output only, so to define how links to JS, CSS and other resources will look like. What you want to do is adjust the URL for an included document for the XSLT processor.

I tried your example and it did work for me for when accessing it locally. I used that view because it is only available on portal root. Do you have some special settings in your theme which might cause this behaviour?

  <replace css:content='#content' css:theme='#css-id' href="/@@overview-controlpanel" />

I think I found the corresponding parts in the diazo sources:

  1. When the document is normalized, the include directive will be applied.

  2. include creates an xsl:apply-templates structure, as defined here.

So you might be able to achieve the same by using document() directly and inserting the $portal_url variable.

I also found this thread on SO, which could help.

Edit: the diazo-base-document variable is defined here: https://github.com/plone/diazo/blob/master/lib/diazo/emit-stylesheet.xsl#L72

thanks for your detailed reply thomas. iiuc you're saying that /@@some-view will lead to a request to the plonesite in any case.
maybe my diazo rules are applied to some resource that should be unthemed (some css or whatever) and these requests cause the error...
the xlst:for-each select stuff is a little bit too in-depth for me atm. i'll try this out in my project when time allows it and report back here.

Yes. If you include external content, that content needs to be parsed, processed and than transformed with your rules, just like regular content. So the XSLT preprocessor needs to have the correct URL to that document (using the document function). And adding $portal_url as a prefix to your @href url does not work in that case. It has nothing to do with themed or un-themed content or CSS.

Could you please point to a (minimal) example of a theme that shows the behavior you are describing? Is your theme installed in the file system or uploaded via zip file?

Hello!
I have a question about the diazo rule. I tried to set the portal_url in the head manually. It doesn't work in the main-template (don't ask :wink: ). While searching the web for ideas, I found this thread.
I need a <script type="text/javascript"> PORTAL_URL = "https://mysite.de";</script> in the html head, so I tried to put a rule like:

<after theme-children="/html/head">
    <script type="text/javascript">PORTAL_URL = &quote; <xsl:value-of select="$portal_url" /> &quote; ;</script>
  </after>

but all I got is:
runtime error, element 'variable' [105:0]
XSLT-variable: Redefinition of variable 'tag_text'. [0:0]

Do you have any ideas for me? I am just a diazo beginner...
The problem is, that I need the quotes before and after the <xsl:value-of select="$portal_url" /> and I can't get it to work.