Variable 'page-types' has not been declared.
This is an open discussion with 4 replies, filed under Troubleshooting.
Search
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.
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:
I know this is wrong, because the structure of page types in the debug is:
So I need to reference the
item
underpage-types
, but the error I encounter when I run this page is:So accessing the
item
is sort of a problem for later. If I switchsite-mode
forpage-types
in my master template, I don't get an error and can make the meta tag show as expected. So what is special aboutpage-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.