3214 Posts in 848 Topics by 810 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 969 Views |
-
> and < Rendered in Template Instead of <>

10 March 2012 at 5:44am
Hi,
I am having a hell of a time rendering a $Title variable in the template which contains HTML. Somewhere between the controller and the template
are being replaced with< and >
as well as many other characters. I've tried absolutely everything to prevent this and to re-replace them but to no avail. The title is plain text in the database, but I have some titles which are Tweets, and so in the controller, in my DataObject::get() result I am parsing them to change the parts that are supposed to be links into links. They come back from the parser perfectly:< and >
horngroup: <a href="http://twitter.com/#!/search?q=%23Apple" target="_blank">#Apple</a> Announces A $499 Retina-Equipped <a href="http://twitter.com/#!/search?q=%23iPad" target="_blank">#iPad</a> (It’s Just Called iPad) <a href="http://t.co/cFPe1HPg" target="_blank">http://t.co/cFPe1HPg</a> <a href="http://twitter.com/#!/search?q=%23appleevent" target="_blank">#appleevent</a>
But when I render $Title in the template, it looks like this:horngroup: <a href='http://twitter.com/#!/search?q=%23Apple' target='_blank'>#Apple</a>’s new <a href='http://twitter.com/#!/search?q=%23iPad' target='_blank'>#iPad</a>: 9 features that matter <a href='http://t.co/IOwFyCii' target='_blank'>http://t.co/IOwFyCii</a>
First of all, why is this happening, and second, how can I stop it? It seems I need a method ion the template itself to render it as HTML but I can't figure it out. Any help out there?
$stream_items = DataObject::get($table,
"`Category`.`CategoryFilterURL` = '".$url."'","Date DESC",
"LEFT JOIN `".$table."_Categories` ON `".$table."_Categories`.`".$table."ID` = `".$table."`.`ID`
LEFT JOIN `Category` ON `Category`.`ID` = `".$table."_Categories`.`CategoryID`",
$limit);
foreach($stream_items as $stream_item) {
$IsTweet = false;
// if is Tweet
if($stream_item->ClassName=="ExternalBlogEntry") {
$IsTweet = true;
$text = $stream_item->Title;
$text = $this->parseTweet($text);
$stream_item->Title = $text;
}
$stream_item->IsTweet = $IsTweet;
}
return $stream_items;The Title is a property within the $stream_items object.
Thanks,
Garrett -
Re: > and < Rendered in Template Instead of <>

12 March 2012 at 9:20pm
Every field you output to the template is run through XML() to make sure it is HTML sure it doesn't cause trouble with XSS. If you field contains HTML which you want to be rendered, ensure it is a 'HTMLText' data type rather than Varchar.
-
Re: > and < Rendered in Template Instead of <>

13 March 2012 at 3:56am
Hi @willr, thanks for replying - I had a feeling this was the issue, though I am very reluctant to modify core files. The Title field is declared in SiteTree.php. Is there a way to overload this field in mysite code, in _config.php or otherwise?
//Garrett
-
Re: > and < Rendered in Template Instead of <>

13 March 2012 at 12:32pm
Create a new variable for it and add it to the casting list
static $casting = array(
'HTMLTitle' => 'HTMLText'
);function getHTMLTitle() {
return $this->Title;
}Then use $HTMLTitle rather than $Title.
-
Re: > and < Rendered in Template Instead of <>

20 March 2012 at 4:52am
Done-zo. Thanks as always @willr.
//Garrett
| 969 Views | ||
|
Page:
1
|
Go to Top |


