Hels

I can’t do it as a different page in the cms cos it needs to be the same url

Hels

It was all working fine until I needed to be able to change the Layout part of 1 page type dependent on the group of the person viewing it

Hels

my theme.yml is like this:

  1. ---
  2. Name: mytheme
  3. ---
  4. SilverStripe\View\SSViewer:
  5. themes:
  6. - '$public'
  7. - '$default'
  8. SilverStripe\i18n\i18n:
  9. default_locale: 'en_GB'
Hels

Yes, http://Page.ss is just in template. For every other page type that has just 1 layout I have its layout template file in templates\posOrg\Layout & it uses the main http://Page.ss with the correct Layout template

Hels

thats what I was trying before, but it was using the Page template & ignoring the Layout part. right now I have a http://SignupsPageForChapmans.ss in BOTH my templates\posOrg (this one is identical to http://Page.ss not in namespace) AND templates\posOrg\Layout folders. & that’s how I’ve got it to work

Hels
  1. public function index() {
  2. $member = Security::getCurrentUser();
  3. $chapManGroup = Group::get_one(Group::class, ['Title' => 'ChapterManagers']);
  4. if ($member->inGroup($chapManGroup->ID)) {
  5. return $this->renderWith('posOrg\SignupsPageForChapmans');
  6. }
  7. else {
  8. return $this->renderWith('posOrg\SignupsPage');
  9. }
  10. }
Hels

i know right?! but google won’t tell me the right way

Hels

I have fixed my template issue from earlier today BUT it is not a good solution & I can foresee trouble in future… I ended up having to create 2 new page-type templates that are identical to http://Page.ss just to be able to have the Layout templates changed by the renderwith()’s in my if. I’m sure that can’t really be the right way - like what happens if I want to change something in the main Page template in future, i’ll need to do it in all 3 files. I thought the point of the Layout was to only need 1 master Page template???