Silverstripe - Different tabs and fields per page -
in silverstripe 3.1 possible add different tabs , fields on page example.
and different tabs , fields on services page example.
about page - images tab / attachments tab
services page - images tab / attachments tab / staff person tab
the following code example. have added if statements around snippet work. seems work pages showing same tabs on pages.
i've been doing video lessons on silverstripe website , can see can create page types need know if can achieve without having create page types.
// want on page // if page=about { class page extends sitetree { private static $has_one = array ( 'photo' => 'image', 'brochure' => 'file', ); public function getcmsfields() { $fields = parent::getcmsfields(); $fields->addfieldtotab('root.images', $photo = uploadfield::create('photo')); $fields->addfieldtotab('root.attachments', $brochure = uploadfield::create('brochure')); return $fields; } } // want on services page // } elseif page=services { class page extends sitetree { private static $has_one = array ( 'photo' => 'image', 'brochure' => 'file', 'staff person' => 'image', ); public function getcmsfields() { $fields = parent::getcmsfields(); $fields->addfieldtotab('root.images', $photo = uploadfield::create('photo')); $fields->addfieldtotab('root.attachments', $brochure = uploadfield::create('brochure')); $fields->addfieldtotab('root.staff', $staff = uploadfield::create('staff')); return $fields; } } // } class page_controller extends contentcontroller { private static $allowed_actions = array(); public function init() { parent::init(); } }
i recommend use individual page types want do.
however, if want use 1 page type can use if statement in getcmsfields
function display different fields.
in example code check urlsegment
, although check else title
.
class page extends sitetree { private static $has_one = array ( 'photo' => 'image', 'brochure' => 'file', 'staff person' => 'image', ); public function getcmsfields() { $fields = parent::getcmsfields(); if ($this->urlsegment == 'about' || $this->urlsegment == 'services') { $fields->addfieldtotab('root.images', $photo = uploadfield::create('photo')); $fields->addfieldtotab('root.attachments', $brochure = uploadfield::create('brochure')); } if ($this->urlsegment == 'services') { $fields->addfieldtotab('root.staff', $staff = uploadfield::create('staff')); } return $fields; } }
Comments
Post a Comment