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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

renderWith()


Go to End


3 Posts   2859 Views

Avatar
Wilson

Community Member, 63 Posts

9 July 2012 at 4:36am

Hi everyone,

I have a Portfolio page type (PortfolioPage.ss) that in one condition needs to render as a Home page (HomePage.ss). In my PortfolioPage.php controller, I have:

public function index() {
    return $this->renderWith(array('HomePage', 'Page'));
}

(condition will be added later)

I'm using the GET var 'debug_request' flag, and I can see this:

Debug (line 202 of SSViewer.php): Final template selections made: array (
'Layout' => '.../themes/oms/templates/Layout/HomePage.ss',
'main' => '../themes/oms/templates/Page.ss',
)

Which seems correct. However, in the rendering there's no data passed to HomePage.ss. Also, the $ClassName var is still 'PortfolioPage'.

This is in 2.4.7. Could anyone advise what the final step is to actually render the Portfolio page as Home page? I think I'm close.

Thanks!
Wilson

Avatar
Willr

Forum Moderator, 5523 Posts

9 July 2012 at 4:01pm

Which seems correct. However, in the rendering there's no data passed to HomePage.ss. Also, the $ClassName var is still 'PortfolioPage'.

Of course $ClassName is still portfolio as all you're doing is changing the 'view' not the data. If you wish to also override data then using customize.

public function index() {
return $this->customise(new ArrayData(array(
'ClassName' => 'HomePage'
)))->renderWith(array('HomePage', 'Page'));
}

Avatar
Wilson

Community Member, 63 Posts

9 July 2012 at 4:11pm

Edited: 09/07/2012 4:11pm

Ah, I see! Thanks Willr! I had played with 'customise' earlier but couldn't quite get it. Thanks. Best, Wilson