Silverstripe 4 and namespacing - where do the templates go?

Keywords:silverstripe  4 


I am upgrading a 3.x site to 4.x. All seemingly going fine and this morning I could actually load my site after upgrading the core framework and other modules.

I have just been through the Upgrading process found here and completed the part where I namespace all custom files in /mysite. Which I have done, with the exception of Page.php and PageController.php.

The issue I am having is since doing this namespacing, no page can find any template in the system. All pages use /framework/templates/SilverStripe/Control/ (confirmed by markup in the source).

There is some very brief discussion in the upgrade doc that goes into templates, but very little. And I've spent the day trying to find tutorials on what the docs might mean by the incomplete statement:

Core template locations have moved - if you’re including or overriding these (e.g. for FormField templates) please adjust to the new paths.

(It's incomplete because it doesn't go on to say what "new paths" actually are.)

If you have a file /mysite/code/Page.php (with no namespace), would you expect the template in /mysite/template/ to load? In my case, it doesn't. If you had another page called HomePage that extended Page.php, but had the namespace Vendor\MySection, where would you expect to find the template in the file system?

Edit: Example of what is not working:

  • Page.php - no namespace
  • HomePage.php - namespace Vendor\MyProject

I have tried the following structure in both my /themes/[themename]/templates directory and /mysite/templates directory:

In either case, neither the template, or the template is picked up. The page is presented by

The only way I have got this to work is by removing namespacing from ALL pages and following the structure normally found in SS3.

Edit 2: Just the contents of my config.yml

    - 'mytheme'
    - '$default'

1 Answer: 

The templates should also be "namespaced";

The template dir in my latest SS4 project looks like


  • global site structure incl. head and body tags
  • Layout
    • $Layout of Page.php
  • Includes
    • ...
  • Vendor: my project's name
    • Includes: stuff that gets included in other templates
    • gets included via <% include Vendor/PageGallery %>
    • Pages: for Vendor\Pages Namespace
    • Layout
    • for Vendor\Pages\FooPage class which gets used for $Layout in the global template

TBH the first try was a lot of WTF and trial and error