Templatemanifest getTemplate

21 views
Skip to first unread message

Nivanka Fonseka

unread,
Dec 5, 2013, 12:26:14 AM12/5/13
to silverst...@googlegroups.com
Hello,

I was trying to override some templates in the theme folder which were also in the mysite folder. but this was not wokring. and i found out that 

TemplateManifest::getCandidateTemplate function checks in the following order for templates. 

1. project folder
2. theme

this means that none of the template files which are in the mysite folder (for most occasions) cannot be overriden. 

I am not sure why this checks the templates this way, but I think it has to be the other way round isnt it ?

1. theme
2. project folder
3. any other place 

cheers 

--
Nivanka Fonseka
Senior Software Engineer

Skype: nivanka.fonseka
Twitter: @nivankafonseka

Daniel Hensby

unread,
Dec 5, 2013, 5:33:56 AM12/5/13
to silverst...@googlegroups.com
I can't tell you for certain as I'm not core dev, but my inferred reasoning for this is so that users can override templates in a modular way without having to edit "core" files.

For example. If I use a thirdparty theme or external one where I can't (shouldn't) edit the templates for whatever reason, I can override those templates without editing the theme directly (thus making upgrades easier) and simply placing one in mysite.

The order of mysite > themes > modules is a sane one to me, if you want to be able to create modular and stand alone code. I've relied on this order of priority many times and has never seemed counter intuitive.

I definitely would not be in favour of changing that order.

Dan Rye

unread,
Dec 5, 2013, 7:48:54 AM12/5/13
to silverst...@googlegroups.com
Themes are more generic than your project MySite so MySite should take precedence.

Sent from Mailbox for iPhone


--
You received this message because you are subscribed to the Google Groups "SilverStripe Core Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to silverstripe-d...@googlegroups.com.
To post to this group, send email to silverst...@googlegroups.com.
Visit this group at http://groups.google.com/group/silverstripe-dev.
For more options, visit https://groups.google.com/groups/opt_out.

Ryan Wachtl

unread,
Dec 5, 2013, 2:50:58 PM12/5/13
to silverst...@googlegroups.com
The expected behavior is that templates in your project folder (mysite) will take priority over those in a theme folder. This works great for Includes but does not work if you want to override Layout templates. For example if you have 

```
themes/simple/templates/Page.ss
themes/simple/templates/Layout/Page.ss
```

If you try to override the layout template with a file in `mysite/templates/Layout/Page.ss` then `framework/templates/Controller.ss` is used as the main template rather than `themes/simple/templates/Page.ss`.

Conversely, if you try to override the main template in `themes/simple/templates/Page.ss` with `mysite/templates/Page.ss` then the Layout templates are not picked up from the theme anymore.

- Ryan

Ryan Wachtl
Twitter. @ryanwachtl

Ryan Wachtl

unread,
Dec 5, 2013, 5:30:15 PM12/5/13
to silverst...@googlegroups.com
I’ve found that the reason for the strange behavior when main/Layout templates are split between the project and theme folders is the logic within TemplateManifest::getCandidateTemplate

If either the main or Layout templates (for instance Page.ss) are found in the project folder, then the project array key is returned as the candidate templates, thus ignoring any candidate templates in the theme folder.

I have changed this behavior by checking both the project and theme for candidate templates, merging them (with project still having priority), and then returning the resulting merged array of templates.


I feel that it makes overriding templates from within your project folder more powerful and predictable.

- Ryan

Ryan Wachtl
Twitter. @ryanwachtl

Reply all
Reply to author
Forward
0 new messages