Jump to:

3447 Posts in 1032 Topics by 872 members

Template Questions

SilverStripe Forums » Template Questions » Double HTML encoding

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

Page: 1
Go to End
Author Topic: 632 Views
  • cmc
    Community Member
    23 Posts

    Double HTML encoding Link to this post

    Basically my function is setting a Text string that has HTML entities encoded. When this is output on the public page the entities have been encoded again, so for example, & becomes & and ' becomes '

    I've tried using html_entity_decode() and a custom function to decode the string prior to sending it to the template. I also tried changing the class from Text to HTMLText. Finally I tried .XML and .RAW in the template. All of those methods still produce double encoding.

    Sorry if this has already been answered. I've spent several hours searching the SS Forum and Internet prior to posting here.

    Here is the relevant code snippet setting the string in the function:

    $post_text = new Text('PostText');

    $output->push(new ArrayData(array(
       'PostText' => $post_text

  • cmc
    Community Member
    23 Posts

    Re: Double HTML encoding Link to this post

    In case anyone else runs into this problem, this is how I fixed it. The only changes are in the first two lines of the original code.

    $post_text = new HTMLText('PostText');

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.