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.

General Questions

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

Multiple templates for single page


Reply

4 Posts   1149 Views

Avatar
EdP

28 August 2010 at 2:25am Community Member, 13 Posts

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.

Avatar
banal

28 August 2010 at 2:59am (Last edited: 28 August 2010 3:01am), Community Member, 901 Posts

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.

Avatar
EdP

28 August 2010 at 4:05am Community Member, 13 Posts

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

Avatar
banal

28 August 2010 at 4:31am Community Member, 901 Posts

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

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