Jump to:

22976 Posts in 11702 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » renderWith()

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

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

Page: 1
Go to End
Author Topic: 1312 Views
  • Wilson
    Avatar
    Community Member
    63 Posts

    renderWith() Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: renderWith() Link to this post

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

  • Wilson
    Avatar
    Community Member
    63 Posts

    Re: renderWith() Link to this post

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

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