Silverstripe Version: 5.2
I don’t fully understand how to get this HTMLText content with shortcodes rendered.
First what works:
In a dataobject:
private static $db = ['SomeContent' => 'HTMLText'];
In a controller:
$this->customise([
'Layout' => $this->customise([
'Data' => MyDataObject::get_by_id($ID)
])->renderWith('CustomErrors/Closed'),
])->renderWith('Page');
In the (CustomErrors/Closed) template:
<div>$Data.SomeContent</div>
That works fine. This doesn’t:
In a controller:
$this->customise([
'Layout' => $this->customise([
'Data' => MyDataObject::get_by_id($ID)->SomeContent
])->renderWith('CustomErrors/Closed'),
])->renderWith('Page');
In the (CustomErrors/Closed) template:
<div>$Data</div>
$Data
above renders as a string. HTML tags and shortcode tags are visible. $Data.RAW
will render the HTML tags but not the shortcode.
I thought this might be due to it being passed as a string value on this line:
'Data' => MyDataObject::get_by_id($ID)->SomeContent
Which makes sense. I’m not sure how to do it differently. I’ve tried forTemplate
and creating an object and setting that to the template variable:
$test = DBHTMLText::create('SomeContent');
$test->setValue(MyDataObject::get_by_id($ID)->SomeContent);
....
'Data' => $test
....
That results in html tags being parsed without .RAW
in the template but shortcodes aren’t parsed.