Jump to:

3435 Posts in 1026 Topics by 866 members

Template Questions

SilverStripe Forums » Template Questions » [3.1] Template not being rendered / function not being called.

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

Page: 1
Go to End
Author Topic: 489 Views
  • Schippie
    Avatar
    Community Member
    28 Posts

    [3.1] Template not being rendered / function not being called. Link to this post

    I am having an odd problem in one of my Controllers, i have a function that returns a $this->renderWith(...); yet this function is never called even when accessing the URL directly. I have this same technique on various other Controllers where they all work without a problem.

    The Controller:

    class Club_Controller extends Controller
    {
    private static $allowed_actions = array (
    'Form_data',
    'Form_data_submit'
    );

    public function Form_data()
    {
    return $this->renderWith('Settings-Form');
    }
    }

    The settings in routes.yml:

    ---
    Name: clubobject_route
    After: framework/routes#coreroutes
    ---
    Director:
    rules:
    'data/clubobject/': 'Club_Controller'

    The weirdest part is when i place the $this->renderWith(..); in:

    function index(){

    ..

    }

    It does work so its not that it cannot find the template. But for some reason when accessing the URL /data/clubobject/form_data it does not execute the function. Maybe if somebody can tell me what would cause this strange / odd behaviour on this one particular controller since it works fine on all the others.

  • Schippie
    Avatar
    Community Member
    28 Posts

    Re: [3.1] Template not being rendered / function not being called. Link to this post

    I am still experiencing this issue. And i am not sure how to fix the issue. For the first post i resorted to using a page (added to the sitetree) but i rather not do that again.

    Maybe somebody can tell what it is that i am doing wrong but here is what i am trying to achieve:

    - I have a route that points to a controller (with no dataobject attached nor any page attached to it) the class extends from the basic controller class.
    - In this class i have a function init() that renders the page with a selected template.
    - In this template i have a form of which the function is also located inside of the controller class.

    Now i want the form to render using the layout ss template within a page.ss template through the {$layout}. Without creating a page for it. Or else having a way to render the form like a normal page (so no within the layout folder)

    Example:

    Class:

    class TestController extends Controller
    {
    function init()
    {
    $this->renderWith('TestController');
    }

    public function Form()
    {

    //create form
    return $form;
    }

    }

    SS template (located in mysite/templates/layout)

    <h3>test controller title</h3>
    $Form

    Any help would be greatly appreciated.

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: [3.1] Template not being rendered / function not being called. Link to this post

    For one, you'll need to add index as an allowed action to your controller. You shouldn't return the render in init, instead put it in an index function

    private static $allowed_actions = array(
    'index'
    );

    public function index() {
    return $this->renderWIth('TestController');
    }

  • Schippie
    Avatar
    Community Member
    28 Posts

    Re: [3.1] Template not being rendered / function not being called. Link to this post

    I had tried the index before with no luck, though i had never put the index function within the allowed actions. Didn't the documentation state that index is always an allowed action? Or is that just a misread on my behalf.

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