Jump to:

23545 Posts in 19310 Topics by 2888 members

General Questions

SilverStripe Forums » General Questions » Overloading Index() on Page_Controller breaks Shortcode Parsing

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

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

Page: 1
Go to End
Author Topic: 944 Views
  • micahsheets
    Avatar
    Community Member
    164 Posts

    Overloading Index() on Page_Controller breaks Shortcode Parsing Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5511 Posts

    Re: Overloading Index() on Page_Controller breaks Shortcode Parsing Link to this post

    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.

    944 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.