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.

Template Questions /

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

customise function


Go to End


3 Posts   2419 Views

Avatar
rainerh

Community Member, 23 Posts

19 November 2009 at 8:09am

Hello everybody,

as far as I understood the documentation the controller function customise should add variables that I can use in my template file. The tutorial describes this functionality in the context of a search. Now I want to use the customisation if a Page is displayed in general.
I thought I have to place that function into the controller's init method. For example to use "Testtitle" as variable I do:

class Page_Controller extends ContentController {
function init() {
parent::init();
return $this->customise(array('Testtitle' => 'hello world'));
}
}

Unfortunately that does not work. I know that the usual way to this is to create a new controller function Testtitle which retuns "hello world" but the real example is a little bit more complex than the one above and I have to use customise

Thanks in advance

Avatar
bummzack

Community Member, 904 Posts

19 November 2009 at 9:00am

I can't see the advantage of using customize. What is there that you can't do with writing a custom method for your needs?
Eg:

public function TestTitle(){
... do whatever the hell you want
return the result of above;
}

I think the method is more flexible and cleaner than customize

Avatar
rainerh

Community Member, 23 Posts

19 November 2009 at 9:41am

I told you above that I don't want to discuss if it is better to use a simple function or not. My use case is similiar to that of the search use case mentioned in the tutorial. What I want is, if a particular Page type is viewed there should be some kind of search results with predefined keywords.