Jump to:

3445 Posts in 1031 Topics by 872 members

Template Questions

SilverStripe Forums » Template Questions » customise function

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

Page: 1
Go to End
Author Topic: 1624 Views
  • rainerh
    Avatar
    Community Member
    23 Posts

    customise function Link to this post

    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

  • banal
    Avatar
    Community Member
    901 Posts

    Re: customise function Link to this post

    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

  • rainerh
    Avatar
    Community Member
    23 Posts

    Re: customise function Link to this post

    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.

    1624 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.