Jump to:

10843 Posts in 2514 Topics by 1792 members

All other Modules

SilverStripe Forums » All other Modules » Set another main template

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 905 Views
  • m-phil
    Avatar
    Community Member
    33 Posts

    Set another main template Link to this post

    Normally I create a new ExamplePage extends Page to use templates/ExamplePage.ss as another main template.
    But for my module I need one main template for all classes (not the default Page.ss). So I added a page type and its template. Every class extends this new page class, but no class use the template... any idea?
    Also another Page.ss in my module templates folder doesn't work.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Set another main template Link to this post

    This is the way the logic works for template selection:

    Select main template for ClassName:

    - Does theme_dir/templates/ClassName.ss exist?
    - No? Is there a module where templates/ClassName.ss is defined?
    - No? Try again with parent of ClassName.ss (e.g. Page.ss)

    Select layout template for ClassName:

    - Does theme_dir/templates/Layout/ClassName.ss exist?
    - No? Is there a module with templates/Layout/ClassName.ss defined?
    - No? Try again with parent of ClassName.ss (e.g. Page.ss)

    Therefore, if you have a class SomePage extends Page, and you've defined /your_theme/templates/SomePage.ss, it will use the main template SomePage.ss.

    It SomePage extends ParentPage, and SomePage.ss does not exist, it will look for ParentPage.ss. If that doesn't exist, it will fall back on Page.ss. The same logic applies to the main template as it does the Layout template.

  • m-phil
    Avatar
    Community Member
    33 Posts

    Re: Set another main template Link to this post

    Yes, I thought this is the way it goes, but not for me?!
    for example we have
    - module/code/ClassName.php <- extends Page
    - module/code/ClassChildName.php <- extends ClassName

    I have a
    - theme_dir/templates/ClassName.ss
    and a
    - module_dir/templates/ClassName.ss

    ClassChildName isn't a subclass in the sitetree... is this a problem? I don't think so

    An existing page of type ClassName is displayed by ClassName.ss but not its class children like ClassChildName.

    mhm what could it be...

  • UncleCheese
    Avatar
    4085 Posts

    Re: Set another main template Link to this post

    So instead of ChildClassName.ss displaying, what is?

  • m-phil
    Avatar
    Community Member
    33 Posts

    Re: Set another main template Link to this post

    Page.ss of course. there is no ChildClassName.ss, otherwise it would use it, but the next template has to be ClassName.ss, but it uses Page.ss

  • UncleCheese
    Avatar
    4085 Posts

    Re: Set another main template Link to this post

    You might try ?debug_request=1 to get a peek at what is going on inside the template selection process.

  • m-phil
    Avatar
    Community Member
    33 Posts

    Re: Set another main template Link to this post

    thx, I didn't know this debug param to display the process.
    OK I translate it into our example:
    here it goes for ChildClassName extends ClassName and ChildClassName is a subclass in sitetree of OtherClass

    Debug line for SSViewer says:
    Selecting templates from the following list: ChildClassName, OtherClass, Page, ContentController

    What about ClassName?

    905 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.