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

Use different tempales to a single Page Type


Go to End


5 Posts   679 Views

Avatar
Praveen

Community Member, 49 Posts

21 January 2015 at 11:44pm

Edited: 21/01/2015 11:45pm

Hi,
In our company we are using a custom page type ProductionPage which is now need to be modified and include blogs. I am using Silverstripe Blog with ProductionPage

All the new Production page created should include blogs and the old Production page will show in the old format still.

Then problem here is ProductionPage type is referenced on other Page Types to generate reports.

I have two ideas in my mind and I am following one. Is that right way to do

1) Create a new Page Type ProductionBlogType extend BlogHolder and merge with DataList referenced in other pages types.
2) ProductionPage extend BlogHolder and choose templates to display. All the old pages will be set by default to old template .

Please Advice.

Thanks
B L Praveen

Avatar
martimiz

Forum Moderator, 1391 Posts

22 January 2015 at 2:43am

If I get you correctly, I might go with 2) and maybe create an index() function that renders with one of two templates depending on the creation date - or maybe on a UseBlogTemplate boolean that you set to default = true for new BlogPages? Reason being that this just changes the ProductionPages, as per the request, and leaves everything else intact...

Avatar
Praveen

Community Member, 49 Posts

30 January 2015 at 1:41am

Yes you right , Later if I need to move away to create one more template. Then how do I still show the page with the blogs If it extend something new

Avatar
Praveen

Community Member, 49 Posts

5 February 2015 at 9:20pm

Edited: 05/02/2015 9:20pm

@martimiz advice me if it is still possible to renderWith different templates. If we keep on changing the page and extending new page types

Avatar
martimiz

Forum Moderator, 1391 Posts

5 February 2015 at 11:02pm

My answer was based on the specific situation, where you wanted to update the appearance for new ProductionPages but not influence existing pages. Reason: the ProductionPage was already referenced throughout other code...

Normally you would create new pagetypes if you wanted different layouts/functionality.

Having said that, if you want to stay with multiple templates for one PageType, you could easily use a 'TemplateToUse' kind of field in the database. Maybe feed it with a dropdown.

Or, if you want to use a new template from a certain point in time, use a 'ProductPageTemplate' setting in the SiteConfig, and add that to the page when it is newly created - onBeforeWrite, if empty($this->ID)

So many ways :)