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.

Template Questions /

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

Diffrent tabs ( fields ) per page


Go to End


2 Posts   1149 Views

Avatar
Jonnyboy

Community Member, 1 Post

26 April 2015 at 8:18pm

Im only new so please bare with me. I have been doing the lessons and am getting my head around this amazing cms framework.

However i would love to know if i can:

Add 3 tabs to the home page
And then add 2 tabs to the about page

And on each page the tab names and fields within the tabs to be different from the home page to the about page.

I can see you can create page types but is it possible to do what im asking.

Cheers
Jonnyboy

for example: ( Now i know the below dosent work, im just showing you what i want to do within the admin area of the pages app )

<?php

// i want this on about page 

// if page=about {

class Page extends SiteTree {

    private static $has_one = array (        
     'Intro' => 'image',   
     'Main' => 'image',
     'Slide' => 'image',        
    );
    
        public function getCMSFields() {        
        $fields = parent::getCMSFields();
        $fields->addFieldToTab('Root.Images', $intro = UploadField::create('Intro'));
        $fields->addFieldToTab('Root.Images', $main = UploadField::create('Main'));            
        $fields->addFieldToTab('Root.Images', $slide = UploadField::create('Slide'));
        $intro->setFolderName('page-photos/intro');
        $main->setFolderName('page-photos/main');   
        $slide->setFolderName('page-photos/slide');        
        return $fields;         
    }
    
//  } elseif page=home {

class Page extends SiteTree {

    private static $has_one = array (        
     'Slide' => 'image',        
    );
    
        public function getCMSFields() {        
        $fields = parent::getCMSFields();       
        $fields->addFieldToTab('Root.Images', $slide = UploadField::create('Slide'));
        $slide->setFolderName('page-photos/slide');        
        return $fields;         
    }

// }

}
class Page_Controller extends ContentController {
	private static $allowed_actions = array ();
	public function init() {	parent::init();	}
}

Avatar
Pyromanik

Community Member, 419 Posts

11 May 2015 at 10:58pm

You should make new page types for this kind of use case.
Probably name them a bit more generically, it makes more sense if being used outside of a speicifc use case (eg. an 'about' style page being used throughout the site).

See the tutorial on making sub page types, such as a news or staff member page type.

If you're trying to do what I think you are, I can think of better ways.
But as you're learning I'll stick with your example thus far as not to confuse you too much:

class Page extends SiteTree {
	private static $has_one = [
		'Slide' => 'Image'
	];
}
class AboutPage extends Page {
	private static $has_one = [
		'Main' => 'Image',
		'Intro' => 'Image'
	];
}