1
votes

New to SilverStripe and trying to decypher how things work.

I have a field in a page which I used to store some HTML code. When you view their "Holder" page, it loops over each child page and displays them all. The problem I am running into is that when I output the value it's escaping it - so I need to be able to decode it.

<% control Children %>
    <h2>$Title </h2>
    $ExtraHtmlBody <!-- This is escaping when outputting -->
 <% end_control %>

So I tried to add a function inside my Page_Controller, but it seems that I can not call Page_Controller methods from inside the Control loop. I tried moving the function into the Page class, but it doesn't seem to have any data for $this->ExtraHtmlBody. Maybe I'm doing something wrong.

1
What datatype is your "ExtraHtmlBody" in $db? As it contains HTML it probable should be HTMLText or HTMLVarchar. As of Silverstripe 3.1 default casting is Text. doc.silverstripe.org/framework/en/3.1/changelogs/3.1.0munomono
It was just Text. I just tried changing it in my class, and edited the page again and still escaped. Is there anything I need to do to update the changes I make in Page class?Louis W
ehm well, /dev/build - and edit?munomono

1 Answers

2
votes

You data might already be escaped in the database itself. did you check?

Like @munomono said, if you are storing html use HTMLText or HTMLVarchar. You can also try to disable auto-escaping in your template with $ExtraHtmlBody.RAW (at your own risks).

some info here:

Your controller function problem is probably just a scope issue since <% loop %> changes the scope, $Up/$Top might help. But you probably don't need that function anyway.