Hi.
I've added two extra fields to my HomePage. Demo and Demo2. Both are HTMLText. Before I output any data in those fields I need to change all & signs to & or I'll get an invalid XML error. I don't want to escape all HTML entities since the data I store in those fields are HTML snippets with an embed code from youtube.
In my HomePage.php file I added this.
function getDemo() {
return str_replace('&','&',$this->Demo);
}
and in HomePage.ss I just call it using $Demo
But nothing is returned.
I changed the function to
function getDemo() {
return "ABC";
}
and now ABC is returned.
Changed again to
function getDemo() {
return "ABC" . $this->Demo;
}
now the output is ABCABC
I'm not sure if I'm logically doing something wrong. I read this http://doc.silverstripe.com/doku.php?id=datamodel and there they are using $this->Status so I'm guessing I'm doing it right but it still seems like $this->Demo ends up calling getDemo instead of giving me the value stored in Demo.
If I change the function to return $this->Demo2 or if I rename the function to getMyDemo() then it works but then what's the point of overloading it?
Any thoughts or maybe even better any idea on what would be the best way to allow users to copy and paste a youtube embed snippet without them having to change the & to & manually?
Cheers