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

Rendering page with different template


Go to End


1414 Views

Avatar
Jankovsky

Community Member, 2 Posts

29 April 2016 at 12:08am

I know that i have to use customise() and renderWith() functions to deliver all necessary data and set proper template/templates. Usually it works like this:

$this->customise($data)->renderWith(array('SomeTemplateName', ...));

And in this specific scenario $this points to current controller. What if i want to use different controller instead of current one? How to get this external controller? I've tried to use:

$contr = ModelAsController::controller_for($page);
$contr->init();
return $contr->customise($data)->renderWith(array('SomeTemplateName', ...));

But it doesn't work. I'm thinking if moving all rendering code to external Controller was good idea (it's not my code, i have to base on it and make changes).