Silverstripe 4 and namespacing - where do the templates go? - 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/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:
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:
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'

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

Related

Silverstripe not using HomePage.ss as Chrome?

Hi I followed the Silverstripe lesson https://www.silverstripe.org/learn/lessons/v4/working-with-multiple-templates-1, and even tried to download the code from repository but when I tried to create templates/HomePage.ss as chrome Silverstripe still uses Page.ss. Clearly lesson says "It first looks in the main templates/ directory to find the chrome for this page. If it finds HomePage.ss in there, it will select that as your chrome." What is missing?
The issue here is that you are conflating the idea between a Page template, and a HomePage template.
The Page 'chrome' template (as the lesson calls it) resides in templates/ because Page class is not namespaced, or that is it resides in the root namespace.
The HomePage class on the other hand is namespaced, and this must be reflected in the path to the template.
A main template (the 'chrome'), the template should be in templates/SilverStripe/Lessons/
A Layout template should reside in the same base, but with a Layout folder; templates/SilverStripe/Lessons/Layout
This information is featured in the lesson.
I understand you are frustrated, but spreading fear uncertainty and doubt about bugs before finding the answer to your question is not a nice thing to do.
You need to create a few folders in the templates folder, as described in that lesson:
Make a directory called templates/SilverStripe/Lessons. In that directory, create another directory called Layout/. In that directory, create HomePage.ss. The full path should be templates/SilverStripe/Lessons/Layout/HomePage.ss.
So you basically need to move your file from templates/HomePage.ss to templates/SilverStripe/Lessons/Layout/HomePage.ss
Silverstripe is buggy, I got same issue. Just switch to Wordpress.

In Magnolia CMS, how can each component declare its required javascript files?

I am using Magnolia CMS 5.3.4, the STK, and freemarker (FTL) template scripts.
Some components I have defined relies on specific javascript files. Right now, what I do is that I include these javascript files in the main.ftl template script. I am looking for a way to get them included only if the specific component is present on the page.
I tried to use the jsFiles property in Template Definitions, but it seems it works only for page template definition.
The jsFiles property indeed works only for pages not for components. This is because Magnolia wants to include those files in header already, rather than loading them in middle of the body when component gets rendered.
As a general practice I would anyway recommend combining your js files into one (look at for example plugin loader in resources on how this is done) and set longer time for caching such file so that browser downloads all the script just once for the whole site rather then page by page. The bigger js file you are sending over the more overhead you are cutting off from requesting separate files and better the compression of content for transport will work.
HTH,
Jan

How do I load this form theme from my App Bundle? (symfony)

I have an app with the following directory structure in Symfony 2.6
src/
App/
MainBundle/
Forms/
template.html.twig
And I'm trying to use this as a form theme along with the bootstrap3 theme. According to the documentation I can apply multiple themes. So I've updated config.yml to look like this:
# Twig Configuration
twig:
form:
resources:
- 'bootstrap_3_layout.html.twig'
- 'AppMainBundle:Forms:template.html.twig'
However, when I add the second resource I only get a blank page. It must be something to do with the way I'm referencing the template -- I can reference another one of the built-in ones and it works correctly.
Thanks.
Templates need to be saved under the
src/{bundle name}/Resources/views/{subdir}/{twig filename}
e.g.
AppMainBundle:Forms:template.html.twig:
src/App/MainBundle/Resources/views/Forms/template.html.twig

Override template of a Symfony BlockBundle SimpleBlock

I recently configured my website project to use Symfony CMF with Sonata Admin.
I'm now populating my website with random editable simple blocks, but can't figure out the way to override their rendering template.
There are two stacks of templates, once for use with the frontend editing CreateBundle and once without. The one for CreateBundle have a _createphp.html.twig at the end. Are you sure you overwrite the correct template? See https://github.com/symfony-cmf/BlockBundle/tree/master/Resources/views/Block
When I debug such things, i try to edit the template in the vendor folder (make a syntax error, write "HELLO" or whatever) just to see if i am even trying to overwrite the correct template.
In the title of this question you mix sonata and cmf. The cmf block bundle builds on sonata block bundle, but provides a couple of block types. Are you sure you have the paths right?

Separating templates from logic in WordPress

I'm wondering the best way to separate my plugin's templates from the actual logic. Currently I use a series of actions & filters to enable theme authors to alter controls ect from my plugin but it's not very intuitive.
I've heard of template engines like twig but not sure on how big the uptake is on these & whether it might confuse more than it helps.
Does anyone have any experience with this in WordPress?
Thanks
By my experience of plugin development, I have come up with a simple MVC like way separate plugin files. Basically what you can do is use the same folder structure that WordPress core uses. For example, if your plugin name is 'Related Posts' (rp), then the folder structure can be as follows:
wp-content/plugins/root_plugin_folder/rp-admin : This should contain all files which are needed for admin interface of your plugin. Typically the view files for your options page etc.
wp-content/plugins/root_plugin_folder/rp-content : This should contain all plugin's template files. This folder can also store stylesheets, js - basically all that is used within the theme
wp-content/plugins/root_plugin_folder/rp-includes : This is the folder for all model files, includes your plugins core libraries, any other libraries used. Basically pure php code of model or view type.
wp-content/plugins/root_plugin_folder/index.php : This file will be the bootstrap which will have plugin name, description markdown and plugin initiation filters and actions etc.
Hope this helps.
Have you ever used the model-view-controller (MVC) method? Its a method of programming to separate logic from presentation.

Resources