Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Overloading Index() on Page_Controller breaks Shortcode Parsing


Go to End


2 Posts   1424 Views

Avatar
micahsheets

Community Member, 165 Posts

10 February 2011 at 2:19pm

On a site that used to be 2.3.7 I upgraded it to 2.4.4 and found that now when I use the links sidebar in the CMS the links are inserted as shortcode. However since I have overloaded Index() in my controller and

return array(
'Content' => $this->Content,
'Form' => $this->Form
);

The shortcode does not get parsed and so the links in Content don't work. On this site I changed my Index() function to Content() and just return $this->Content after modifying it in the function.

Can we no longer overload Index() in 2.4.4?

Avatar
Willr

Forum Moderator, 5523 Posts

10 February 2011 at 8:34pm

You can still overload it, the issue you're facing is that links aren't being rewritten as the parser jumps in at the template level and it only parses HTMLText fields which in your array it is not, your returning just a string.

Solution is to return a new database object

return array(
'Content' => DBField::create('HTMLText', $this->Content);
);

Though if you aren't changing $this->Content in index you shouldn't even need that line as it will automatically fallback to $this->Content on the object.