Jump to:

5540 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Custom Function Call in Page no working in sidebar

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

Page: 1
Go to End
Author Topic: 348 Views
  • ChurchDude
    Community Member
    19 Posts

    Custom Function Call in Page no working in sidebar Link to this post


    I have defined a custom function that is called by the Content function of the Page_Controller. The function replaces a string with a customer image throughout my site.

    This render works on any page content. However, when I attempt to call the function from within by sidebar that is included in a page via the include statement it does not render. It just shows the text. So what am I doing wrong?

    Here is some code.

    class Page_Controller extends ContentController {

    function Content() {
    $thereturn=str_replace('$PayPalFormsubdomain', $this->PayPalFormsubdomain(), $this->Content);
    return $thereturn ;

    function PayPalFormsubdomain() { return 'some text'; }

    In my Page.ss
    <% include SideNav %>

    In SideNav.ss
    <% control ALLChildren %>
    <% end_control %>

    The result displays:


    Instead of: some text

  • martimiz
    Forum Moderator
    1081 Posts

    Re: Custom Function Call in Page no working in sidebar Link to this post

    When you loop a set of pages like this:

    <% control AllChildren %>
    <% end_control %>

    what you get is a set of Page objects (the DataModel), not Page_Controllers! So from within that loop you don't have access to any controller function and now your template will just display the content as is...

    To fix that, you need to create a function in you Page class, that will do the replacing...

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.