Jump to:

23486 Posts in 18995 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Multiple templates for single page

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: 1132 Views
  • EdP
    Avatar
    Community Member
    13 Posts

    Multiple templates for single page Link to this post

    I have some child pages (Concerts) set up and populated via the CMS, displaying via a Concerts.ss template. An example url would be /concerts/autumn-2010/.

    I would like to display data from extra fields (already stored in the db) via a link on those pages to e.g. /concerts/autumn-2010/rehearsals, so I have a made suitable link in the Concerts.ss template:

    <a href="$URLSegment/rehearsals/">Rehearsals</a>

    Could someone possibly tell me where I go from here. I have a feeling it's renderWith but the following (in Concert.php) just gives me out of memory errors:

    class Concert_Controller extends Page_Controller {
       
       public function rehearsals(){
        return $this->renderWith(array('Concert_rehearsals', 'Concert', 'Page'));
       }
    }


    Many thanks.

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Multiple templates for single page Link to this post

    The method in your controller can be as simple as this:

    public function rehearsals(){
       return array();
    }

    This will make the template-engine use the default naming convention for templates which is: ClassName_action.

    So your template for the rehearsals should be named: Concert_rehearsals.ss

    Update: Don't forget to append ?flush=1 to your URL to flush the template-cache.

  • EdP
    Avatar
    Community Member
    13 Posts

    Re: Multiple templates for single page Link to this post

    banal, thank you so much. I would never have guessed it could be so simple. I trawled the documentation for hours looking for a solution.

    Now all I'll have to do is customise the Breadcrumbs a bit (unless one can pass something in that empty array to set things like the page title?).

    Ed

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Multiple templates for single page Link to this post

    Yep, you should be able to pass custom content via that array.
    So to override the title:

    return array('Title' => 'My custom Title');

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