Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Best practice...

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 2522 Views
  • Nemus
    Avatar
    Community Member
    20 Posts

    Best practice... Link to this post

    I'm wondering what is the best practice for including one template into another? I'm having site for which I want footer to be same across multiple page types/templates but so far I didn't manage to achieve this.
    I'm aware of $layout and $content automatic inclusion but I want single include for all page types (not as $layout or $content)...

    Also is there general include method for page templates?

    Any hints?

  • Sam
    Avatar
    Administrator
    679 Posts

    Re: Best practice... Link to this post

    1) Put your template into templates/includes, for example, templates/includes/MyTemplate.ss

    2) Put <% include MyTemplate %> in the parent template. Don't include the extension.

    3) Visit your page with ?flush=1 to pick up the new template. Note that there's currently a bug -- if you edit MyTemplate.ss it won't recognise the change until you put ?flush=1 on the URL.

  • Nemus
    Avatar
    Community Member
    20 Posts

    Re: Best practice... Link to this post

    Hi Sam,

    I've tried example you gave me but it doesn't work. Template named FooterMenu.ss in my case is never included in main template I've checked manifest file in cache dir and file is found and included into array $_TEMPLATE_MANIFEST... But include in never done. Deleted cached verison of the parent page but no luck...
    Another small thing. If this FooterMenu.ss contains some template code (getMenu() for instance, which existis in parent template) do I need to have page type for it?
    I've tried that also but it didn't work but I want to know for future reference...

  • Sam
    Avatar
    Administrator
    679 Posts

    Re: Best practice... Link to this post

    Hmm.... email me your templates on sam@silverstripe.com and I'll take a look.

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Best practice... Link to this post

    Sam: I was working on a test site on my local machine at home. Everything seems to be working fine, but I also get the <% include blah %> problem too. Nothing ever seems to be getting included.

  • Nemus
    Avatar
    Community Member
    20 Posts

    Re: Best practice... Link to this post

    Sam:
    Somehow include does work now. I didn't do anything (just started writing you an email with templates) just tried again just to be sure before sending an email. Maybe my environment is broken in some less than obvious way which i can't detect...Some hidden cache? Are there any tests to certify that environment is installed properly?

  • Sam
    Avatar
    Administrator
    679 Posts

    Re: Best practice... Link to this post

    Other developers at the office have reported problems with caching and <% include %>d templates. I think I'm going to have to have a look at this for the next release.

    2522 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.