Error Theme Inherited from Barceloneta footer_portlets_count

Hi!

I am trying to theme Plone following https://training.plone.org/5/theming/ttw-advanced-2.html

After creating a new theme that inherits from Barceloneta, I am getting the following error after reloading the home page of the site:

runtime error, element 'if' [148:0]
Variable 'footer_portlets_count' has not been declared. [0:0]
Undefined variable [0:0]

The rules xml displayed after the above three lines that include the string footer_portlets_count are the following:

<xsl:variable name="footer_portlets_count" select="count($footer_portlets)"/>

after "Footer" section

and

<xsl:if test="$footer_portlets_count=1">col-md-12</xsl:if>
<xsl:if test="$footer_portlets_count=2">col-md-6</xsl:if>
<xsl:if test="$footer_portlets_count=3">col-md-4</xsl:if>
<xsl:if test="$footer_portlets_count=4">col-md-3</xsl:if>
<xsl:if test="$footer_portlets_count>4">col-md-4</xsl:if>

after "Move all other footer portlets into doormat area." section

I think all these come from Barceloneta.

Any ideas?

Thanks.

Filipe

I use the following for the replacement:

<!-- Central column with Right Portlets if available -->
<replace css:theme=".content-container" method="raw">
  
  <xsl:variable name="central">                
    <xsl:if test="//aside[@id='portal-column-two']">col-md-9</xsl:if>                
    <xsl:if test="not(//aside[@id='portal-column-two'])">col-md-12</xsl:if>
  </xsl:variable>
    
  <xsl:variable name="right">
    <xsl:if test="//aside[@id='portal-column-two']">col-md-3</xsl:if>
    <xsl:if test="not(//aside[@id='portal-column-two'])">col-md-6</xsl:if>
  </xsl:variable>
    
  <div class="container content-container">
    <div class="row">
      <!-- Main Content -->
      <div class="{$central}">
        <!--- ..... -->
      </div>
      <!-- /Main Content -->
      
      <!-- Right Slot -->
      <div class="{$right}">
        <!--- ..... -->
      </div>
      <!-- /Right Slot -->
    </div>
  </div>
</replace>

I have never seen the 'count'… is it documented somewhere ?
What happens if you declare the variable as:

<xsl:variable name="footer_portlets_count">3</xsl:variable>

Completely unrelated, but you could consider using CSS flex or CSS grid and do it all with CSS (that is what I do)

If i see correctly the $footer_portlets variable is missing .... see the rules.xml on barceloneta master here https://github.com/plone/plonetheme.barceloneta/blob/master/plonetheme/barceloneta/theme/rules.xml#L104-L175

I just ran into this issue and solved it as follows:

  1. replace the filesystem barceloneta theme with a TTW version
  2. in the ttw version, find rules.xml and cut out the section marked with <!-- Footer --> in lines 104-107
  3. paste the two xsl variable definitions footer_portlets and footer_portlets_count below the line <replace css:theme-children="#portal-footer .doormat"> near line 126
  4. rename index.html in your custom theme to theme-index.html
  5. copy index.html from barceloneta to index.html in your custom theme
  6. use the following rules.xml
<?xml version="1.0" encoding="UTF-8"?>
<rules xmlns="http://namespaces.plone.org/diazo"
		xmlns:css="http://namespaces.plone.org/diazo/css"
		xmlns:xhtml="http://www.w3.org/1999/xhtml"
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
		xmlns:xi="http://www.w3.org/2001/XInclude">
  <rules css:if-content="body:not(.userrole-anonymous)">
    <!-- Import Barceloneta rules -->
    <xi:include href="++theme++barceloneta/rules.xml"
		/>
    <after css:theme-children="head">
      <link rel="stylesheet"
		href="/++theme++barceloneta/less/barceloneta-compiled.css"
		/>
    </after>
  </rules>
  <rules css:if-content="body.userrole-anonymous">
    <theme href="theme-index.html"
		/>
    <!-- your customizations go here -->
  </rules>
</rules>

Note: on Plone 5.2 RC4 you will run into this issue when overriding barceloneta: https://github.com/plone/plone.app.theming/issues/160

I was trying to do something similar and got the same error by doing:

<rules css:if-not-content="body.viewpermission-view, body.viewpermission-none">
    <xi:include href="++theme++barceloneta/backend.xml" />
</rules>
<rules css:if-content="body.viewpermission-view, body.viewpermission-none">
    ...
</rules>

Still exploring why this is an error.

The first part actually even doesn't matter. Get the error only by wrapping the main xml with following:

<rules css:if-content="body.viewpermission-view, body.viewpermission-none">
    ...
</rules>

Just ran into the same thing on 5.2. The included barceloneta rules.xml seems to try & set the footer_portlets_count like this:

<xsl:variable name="footer_portlets" select="//footer[@id='portal-footer-wrapper']//div[@class='portletWrapper']/*[not(contains(@id,'portal-colophon')) and not(contains(@id,'portal-footer-signature')) and not(contains(@class,'portletActions'))]"></xsl:variable>
  <xsl:variable name="footer_portlets_count" select="count($footer_portlets)"></xsl:variable>

This of course works on barceloneta itself. I have no idea why it fails on a custom theme that derives from it, changing nothing: My custom TTW theme consists of nothing more than rules.xml importing barceloneta rules, and index.html that's a verbatim copy of the barceloneta one.

This is still wrong, maybe the fix is to include

  <!-- Footer -->
  <xsl:variable name="footer_portlets" select="//footer[@id='portal-footer-wrapper']//div[@class='portletWrapper']/*[not(contains(@id,'portal-colophon')) and not(contains(@id,'portal-footer-signature')) and not(contains(@class,'portletActions'))]"></xsl:variable>
  <xsl:variable name="footer_portlets_count" select="count($footer_portlets)"></xsl:variable>

just before
</rules>?

This is fixed here:
For 5.2: Move 'footer_portlets' and 'footer_portlets_count' variables by sverbois · Pull Request #239 · plone/plonetheme.barceloneta · GitHub
For 6.0: Fix Diazo rule problem with undefined footer_portlets and footer_port… by thet · Pull Request #322 · plone/plonetheme.barceloneta · GitHub

2 Likes