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

Multiple templates for single page


Go to End


4 Posts   2019 Views

Avatar
EdP

Community Member, 14 Posts

28 August 2010 at 2:25am

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
bummzack

Community Member, 904 Posts

28 August 2010 at 2:59am

Edited: 28/08/2010 3:01am

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

Community Member, 14 Posts

28 August 2010 at 4:05am

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
bummzack

Community Member, 904 Posts

28 August 2010 at 4:31am

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

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