Aaryn
Aaryn

Reputation: 1643

Silverstripe 4 and namespacing - where do the templates go?

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/Controller.ss (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/Page.ss 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:

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

Page.ss
Vendor
   MyProject
      Layouts
         HomePage.ss

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

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

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

Upvotes: 2

Views: 626

Answers (1)

wmk
wmk

Reputation: 4626

The templates should also be "namespaced";

The template dir in my latest SS4 project looks like

templates

  • Page.ss: global site structure incl. head and body tags
  • Layout
    • Page.ss: $Layout of Page.php
  • Includes
    • Header.ss
    • ...
  • Vendor: my project's name
    • Includes: stuff that gets included in other templates
    • PageGallery.ss: gets included via <% include Vendor/PageGallery %>
    • Pages: for Vendor\Pages Namespace
    • Layout
    • FooPage.ss: 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

Upvotes: 2

Related Questions