mtrebron
(Norbert )
July 5, 2019, 1:39pm
1
Hi all,
I have the following use case:
My diazo theme will include one of more theme html files depending on the part of the site which is visited. I am able to create a rule which conditionally loads a html template.
I want to include a common html fragment mega-menu.html in any of the templates rather than duplicating the html.
|--[html]--|--index.html
| |--services.html
| |--blog.html
| |--mega-menu.html
|
|--rules.xml
If I replace the nav element from one of the template with my mega-menu nav e.g. like this:
<replace css:theme="nav" css:content="nav" href="++theme++my.theme/html/mega-menu.html" />
the fragment is included but I am unable to apply any further customizations.
How can this be done?
pigeonflight
(David Bain (dbain.com))
July 5, 2019, 6:15pm
2
@mtrebron ,
It will take some slight refactoring but you can get what you want done with collective.themefragments.
More info here:
mtrebron
(Norbert )
July 5, 2019, 7:26pm
3
Hi David,
Cheers for the link! I looked at that, and the jbot variant, but decided against it because it adds another layer of complexity. Preferably, a designer who can create a bootstrap based theme but does not necessarily know Plone or PageTemplates should be able to maintain/extend the current theme.
While typing, I revisited this stackoverflow question
This seems to do what I want, but only if used in the top-level rules element
<replace css:theme="nav">
<xsl:call-template name="nav-replacement" />
</replace>
<xsl:template name="nav-replacement" match="nav">
<xsl:element name="nav">
<xsl:apply-templates select="document('++my.theme/html/mega-menu.html',$diazo-base-document)/html/body/div/nav/node() "/>
</xsl:element>
</xsl:template>
<drop css:content="nav .navbar-toggle" />
I'll see how far I get if I attempt my replace again in the root rules...
Edit: the original replace rule does not work in the top-level root element.
mtrebron
(Norbert )
July 5, 2019, 7:54pm
4
with this simplified version, dropping the element works but redefining does not...
<replace css:theme="nav">
<xsl:apply-templates select="document('++my.theme/html/mega-menu.html',$diazo-base-document)/html/body/div/node() "/>
</replace>
<replace css:content="nav .navbar-brand" css:content="#portal-logo"/>
Attribute css:content redefined [11:68]
Rules document could not be parsed!
mtrebron
(Norbert )
June 29, 2024, 1:18pm
5
Reminder to self in the distant future, for when I find myself again looking for an answer to this...
http://docs.diazo.org/en/latest/advanced.html#inline-xsl-directives
Inline XSL directives must be placed directly inside the root <rules>
tag and are applied unconditionally.
The following snippet works only when it is placed directly in the main rules tag inside the main rules.xml document.
This makes Plone awesome:
<xsl:template match="//ul[@id='portal-globalnav']/li/a">
<a>
<xsl:apply-templates select="./@*"/>
<span>Plone is Awesome
<xsl:value-of select="." />
</span>
</a>
</xsl:template>
While neither of these approaches do:
<rules css:if-content=".easyformForm">
<xsl:template match="//ul[@id='portal-globalnav']/li/a">
<a>
<xsl:apply-templates select="./@*"/>
<span>Plone is Awesome
<xsl:value-of select="." />
</span>
</a>
</xsl:template>
</rules>
or...
<rules css:if-content=".easyformForm">
<xi:include href="++theme++intranet-theme/rules/easyform.xml" />
</rules>
espenmn
(Espen)
July 1, 2024, 8:22am
6
Slightly related:
I have this working:
manifest.cfg:
spot_2 = python:portal_state.portal().portal_registry['medialog.dutchestheme.interfaces.IMedialogDutchesThemeSettings.rules']=='spot_2'
<rules if="$spot_2">
<xi:include href="++theme++dutchestheme/spot_2.xml"/>
</rules>
That said: I think manifest values are only 'read first time', if not you could maybe get som value from '/view/something' ?