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.

Template Questions /

[3.1] Template not being rendered / function not being called.


Reply


4 Posts   572 Views

Avatar
Schippie

Community Member, 37 Posts

2 October 2013 at 10:37pm

Edited: 02/10/2013 10:40pm

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.

Avatar
Schippie

Community Member, 37 Posts

5 November 2013 at 12:51pm

Edited: 05/11/2013 12:52pm

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.

Avatar
Willr

Forum Moderator, 5513 Posts

6 November 2013 at 5:50pm

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');
}

Avatar
Schippie

Community Member, 37 Posts

6 November 2013 at 9:33pm

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.