0

By default, each template in expression engine is an entire template. Is there a way to set a global template, and have each template be inserted as the content section of that template?

ie. .template.php:

<html>
  <head>
  </head>
  <body>
    {embed:currentpagecontent}
    <footer>
    </footer>
  </body>
</html>

The only way I can think of doing it is to have common elements and embed them on every template - like so:

{embed:'.header.php'}
{embed:'.navbar.php'}

<h1>ipsum lorem</h1>

{embed:'.footer.php'}

it just seems messy having the same prefix and suffix on every template

(nb. this question sounds annoyingly confusing due the dual meaning of the word 'template' in expression engine!)

2

This is a common question and there is a technique you can use with the add-on "Stash." It's already been described and documented multiple times.

Check out the selected answer for this other, similar question: How to use a common template for all pages?

| improve this answer | |
  • perfect - i'll check this out now! – stef May 10 '13 at 10:57
0

You absolutely could have a single template. Just make 1 template, set it as the 'homepage' of your site then within that apply whatever logic you wish to pull in different embeds or snippets. Though I think it would become a bit messy fairly quickly for anything but the most basic site. It's much simpler to use different template groups.

What is the other meaning of "template" in EE? There's only 1 meaning of template as far as I'm aware.

| improve this answer | |
  • so the recommended approach is to have boilerplate sections that are common to the whole site in hidden templates, and {embed}ding them on every page? – stef May 10 '13 at 10:10
  • (and i just meant that ee templates are tied directly to routing/controller logic - something that i've always tried to keep separate from view logic. it's confusing because i want to keep the routing logic of 'template groups : templates', but not have duplicated content on every 'template' in the whole site) – stef May 10 '13 at 10:15
  • I don't know if it's "recommended" or not but I tend to create partials for things like site headers, footers etc. I probably wouldn't try to do everything on a single template simply because the conditional logic would get over complex for most of the things I build with EE. – foamcow May 10 '13 at 11:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.