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.

Customising the CMS /

Custom Function Call in Page no working in sidebar


Reply


2 Posts   389 Views

Avatar
ChurchDude

Community Member, 19 Posts

11 November 2011 at 9:02am

Hello,

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 %>
$Content
<% end_control %>

The result displays:

$PayPalFormsubdomain

Instead of: some text

Avatar
martimiz

Forum Moderator, 1105 Posts

12 November 2011 at 6:59am

Edited: 12/11/2011 7:00am

When you loop a set of pages like this:

<% control AllChildren %>
   $Content
<% 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...