I have a PHP script that runs perfectly fine as a standalone script. It also runs great when ‘including’ it in an EE template, like so
<?php include( $_SERVER['DOCUMENT_ROOT'].'/myscript.php' );?>I am making use heredoc notation in that script (urls obfuscated):
$xsl = <<<EOT
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8" indent="yes">
<xsl:template match="/deals">
<rss version="2.0">
<channel>
<title>Test</title>
<link>http://host.tld/somefeed</link>
<description>The description.</description>
<language>en-us</language>
<xsl:for-each select="deal">
<item>
<title><xsl:value-of select="name"></title>
<link>http://host.tld/somefeed/<xsl:value-of select="id"></link>
<description><xsl:value-of select="background"></description>
<xsl:value-of select="created-at"></pubDate>
</item>
</xsl:for-each>
</channel>
</rss>
</xsl:template>
</xsl:stylesheet>
EOT;When I paste the entire script into an EE template it does not work. After some testing, I found that the culprit was the $xsl variable. It failed to parse in a subsequent function call. Apparently something in the template gets mangled before my PHP code gets a chance to execute.
I also tried to replace the above with this in the template - but that also fails (PHP parsing set to output):
$xsl='{embed="somefeeds/somexsl"}';
// more code…The somexsl template was created as a ‘static’ template.
The only work-around I found so far, is to encode the literal string (html_encode) and where I use it in the php I run it through html_entity_decode($xsl) first.
Not exactly pretty, but I’d like to understand why the other options do not work. It appears as though the EE Template Parser does something I do not know or do not understand. I could most certainly make a plugin, but this seemed like a case where some simple php code in a template should do.
Thanks for any feedback.
Juergen