Jump to:

3444 Posts in 1030 Topics by 871 members

Template Questions

SilverStripe Forums » Template Questions » Escaping < in templates

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 441 Views
  • jayslippy
    Avatar
    Community Member
    10 Posts

    Escaping < in templates Link to this post

    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?

  • jayslippy
    Avatar
    Community Member
    10 Posts

    Re: Escaping < in templates Link to this post

    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.

    441 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.