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!)

0

2 Answers 2

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?

1
  • perfect - i'll check this out now!
    – stef
    Commented May 10, 2013 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.

3
  • 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
    Commented May 10, 2013 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
    Commented May 10, 2013 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
    Commented May 10, 2013 at 11:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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