Search

I want to add a noindex meta tag to any page with a page type of 'no-index'. I put this in my master template:

<xsl:if test="$page-types = 'no-index'">
    <meta name="robots" content="noindex, follow"/>
</xsl:if>

I know this is wrong, because the structure of page types in the debug is:

<data>
    <params>
        ...
        <page-types>
            <item handle="no-index">no-index</item>
        </page-types>
        <site-mode>live</site-mode>
    </params>
</data>

So I need to reference the item under page-types, but the error I encounter when I run this page is:

XSLTProcessor::transformToXml():
    Variable 'page-types' has not been declared.

So accessing the item is sort of a problem for later. If I switch site-mode for page-types in my master template, I don't get an error and can make the meta tag show as expected. So what is special about page-types? Why can't I access this information?

If I put a blank variable declaration for page-types at the top of the template I don't get the error, but I also don't get the condition evaluating like I want.

Thanks for reading.

You can always change the conditional from $page-types = 'no-index' to /data/params/page-types/item[@handle = 'no-index'] which does not rely on the variables but on the xml directly.

However, setting the variable yourself should also work. Are you sure you haven't used a value with the declaration? <xsl:variable name="page-types"/> should do the trick.

I did try <xsl:variable name="page-types"/> (copied and pasted, so definitely no value assigned) and that clears up the not defined error but it still doesn't allow me to access the value shown in the debug mode (it comes up blank instead). If I use the XML method of accessing it, my conditional works fine and I get the desired result. I guess I was hesitant to use this method in case it causes problems on update. Hopefully Symphony doesn't decide to go moving these things around.

I'll call it fixed for now, thanks for your reply!

Oh, by the way, the variable declaration should go all the way on the top, right after you've declared that you're building a stylesheet. When you're putting it inside a template declaration it will get the results you are currently getting.

To clarify:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl">
    <xsl:output method="xml"
        doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
        doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
        omit-xml-declaration="yes"
        encoding="UTF-8"
        indent="yes" />

    <xsl:variable name="page-types"/>

    <xsl:template match="/">
        rest goes here.
    </xsl:template>
</xsl:stylesheet>

this is what I am using all the time.

Yes, I had it right after my import statements, before the xsl:template match="/".

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details