Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions /

Escaping < in templates


Reply


2 Posts   499 Views

Avatar
jayslippy

Community Member, 10 Posts

1 March 2012 at 12:18am

Edited: 01/03/2012 12:19am

I'm outputing an XML file for excel which requires second line:

<?mso-application progid="Excel.Sheet"?>

I've looked around for a couple of hours but can't find a reference to the escape character for "<" and ">" in the templates, to stop silverstripe converting it to:

SSVIEWER;
mso-application progid="Excel.Sheet";
$val .= <<<SSVIEWER

Can somebody let me know the correct method of displaying the line literally?

Avatar
jayslippy

Community Member, 10 Posts

1 March 2012 at 3:35am

I've gone with an alternative solution to my problem for now. I've gone into the SSViewer.php code in sapphire/core and added some lines to the parsing code. The code treats the xml header beginning "<?xml" as a special case and I've added lines to do the same to my "<?mso-application" lines.

$content = ereg_replace('<\?xml([^>]+)\?' . '>', '<##xml\\1##>', $content);
$content = ereg_replace('<\?mso-application([^>]+)\?' . '>', '<##mso-application\\1##>', $content);

$output = ereg_replace('<##xml([^>]+)##>', '<' . '?xml\\1?' . '>', $output);
$output = ereg_replace('<##mso-application([^>]+)##>', '<' . '?mso-application\\1?' . '>', $output);

It does work, but I don't like playing with the core code like this. If somebody can suggest an alternative solution, such as a way of escaping my '<' or '?' characters to print my mso-application line, it would be a big help.