4

Seems to be precious little info out there on how templates should be structured. I asked this question earlier but I think I can ask it better with code samples and remove my earlier attempt:

mysite/_config/theme.yml

SilverStripe\View\SSViewer:
  themes:
    - 'mytheme'
    - '$default'

mysite/code/Page.php

<?php

use SilverStripe\CMS\Model\SiteTree;

class Page extends SiteTree {

}

mysite/code/PageController.php

<?php

use SilverStripe\CMS\Controllers\ContentController;

class PageController extends ContentController {

}

mysite/code/pages/HomePage.php

<?php

namespace Vendor\MainSite;

use Page;

class HomePage extends Page {

}

/mysite/code/controllers/HomePageController.php

<?php

namespace Vendor\MainSite;

use PageController;

class HomePageController extends PageController {

}

Then I have my theme. Structure like so:

theme
   mytheme
      templates
         **Page.ss**
         Layout
         Includes
         Vendor
            MainSite
               Layout
                  **HomePage.ss**

Assume that Page.ss contains $Layout. The issue I have is Page.ss is never picked up. I have confirmed Silverstripe is loading vendor/silverstripe/framework/templates/SilverStripe/Control/Controller.ss instead. I have tried various locations for Page.ss, including inside the same Vendor directory. I have also moved the entire structure to /mysite/templates.

The only way I have got the above to load a template is by removing namespacing from HomePage.php and simply following the SS3 structure for templates.

Aaryn
  • 1,601
  • 2
  • 18
  • 31
  • 1
    Looks good to me. Did you do a `dev/build`? If you don't have it yet, you should also put a `Page.ss` in `theme/mytheme/templates/Layout`, so that you get a login form to show up etc. – bummzack Mar 01 '18 at 07:42
  • Multiple dev/builds. And manual destruction of the /tmp/cache. This simply doesn't work. – Aaryn Mar 02 '18 at 01:17
  • 1
    Unfortunately this isn't reproducible. Are you sure you've included everything exactly as it is in your project? For example, is your vendor actually "Vendor" ? – scrowler Mar 02 '18 at 03:05
  • I think I discovered the issue just now. Adding namespaces to these classes broke the ClassName for the pages themselves. So the pages weren't actually looking for their templates at all. I had to use legacy.yml to force SS to alter the the old ClassNames to the namespaced ones. https://github.com/silverstripe/silverstripe-upgrader#upgrading-database-references-to-now-namespaced-dataobject-subclasses – Aaryn Mar 06 '18 at 04:09
  • 2
    I also had this issue - but I found that it was resolved by running dev/build after namespacing and logging into the CMS, re-saving and publishing the pages in question. – pingu Jun 27 '18 at 10:57
  • This was really helpful there is still terrible documentation out there for this. Its totally unclear as to the best structure and namespace method. – pinkp Jul 19 '20 at 18:08

0 Answers0