Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive /

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

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

Best practice...


Reply


7 Posts   2643 Views

Avatar
Nemus

Community Member, 20 Posts

26 October 2006 at 7:39pm

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?

Avatar
Sam

Administrator, 685 Posts

27 October 2006 at 11:23am

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.

Avatar
Nemus

Community Member, 20 Posts

4 November 2006 at 12:47am

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

Avatar
Sam

Administrator, 685 Posts

4 November 2006 at 10:09am

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

Avatar
Sean

Forum Moderator, 922 Posts

5 November 2006 at 8:13pm

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.

Avatar
Nemus

Community Member, 20 Posts

8 November 2006 at 3:58am

Edited: 08/11/2006 7:34pm

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?

Avatar
Sam

Administrator, 685 Posts

8 November 2006 at 2:36pm

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.