Jump to:

3393 Posts in 976 Topics by 852 members

Template Questions

SilverStripe Forums » Template Questions » url_handlers and action specific templates

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

Page: 1
Go to End
Author Topic: 1621 Views
  • neros3
    Avatar
    Community Member
    51 Posts

    url_handlers and action specific templates Link to this post

    Hi

    I'm using SS.2.4.

    I want an action called new. But since that is a reservered word I can't make a function called new(). So I've made a url_handler to handle that

    public static $url_handlers = array(
    'new' => 'customnew'
    );

    My template is called: Mypage.ss - and in order to have a specific template for this action I have tried making Mypage_new.ss and Mypage_customnew.ss.
    When accessing the url /Mypage/new none of the templates gets loaded. The only way I can load an action specific template is by calling /Mypage/customnew.

    Anyone knows how to fix this? I suppose I could render the page with a specific template, but thats not preferable.

    Thanks!

  • Terrence Wood
    Avatar
    Community Member
    1 Post

    Re: url_handlers and action specific templates Link to this post

    To use a template that doesn't match your ClassName you will need to load your template:

    class MyPage_controller extends Page_Controller {
    function customnew() {
    $data = DataObject::get('CustomNew');
    return $this->customise($data)->renderWith(array('customnew','Page'));
    }
    }

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