2

This might be really basic, but using a standard Expression Engine install, how do I choose a different design template for a specific channel? I'm not using Structure or anything like that.

I basically have two design templates, one for the front page, and one for articles. I'm displaying a portion of the content of each article on the front page. But want to link to the article itself from the front page. Then I want it to open that article using the other design template. Weirdly enough, I can't find any documentation on that.

3 Answers 3

3

The basics are that a template is based on the URL, so say you have your default template group as "site", "site/index" will be your homepage - so your initial design can go in there. So that you can share elements (header, footer, etc), you might be using embeds to other templates.

But if you create other templates they will then be accessible on URL, so creating another template in the "site" group called "about" can contain completely different design template and be accessible via /about.

This may also mean using different template groups, for example creating a "blog" template group, would mean the URL /blog would go to the "index" of that template group.

Alternatively, you can route it through the "index" template...

{embed="includes/head"}
{embed="includes/header"}
{if "{segment_1}" == ""}
    {!-- HOMEPAGE --}
    {embed="content/homepage"}
{if:else}
    {embed="content/content-page"}
{/if}
{embed="includes/footer"}

The above will share the same header and footer templates, but allow complete freedom in different content templates. 2 new template groups are utilised in the above (includes and content).

You could approach it using

{exp:channel:entries channel="homepage"...}
    HOMEPAGE CONTENT
{/exp:channel:entries}

{exp:channel:entries channel="content"...}
    CONTENT CONTENT
{/exp:channel:entries}

But the overhead would be much greater and not recommended. In the same way that...

site/index template

{exp:channel:entries}
    {embed="content/{channel_short_name}"}
{/exp:channel:entries}

Will embed different templates based on your channel name (other templates would be in the "content" template group and named to match the channel short name). But again, will have the minor overhead of the initial channel:entries just to determine the channel - better to use segment conditionals.

There are many ways to approach EE, some right, some wrong, some clean, some messy, but ultimately it's what you prefer and what works for what you're trying to achieve.

To name but a few places to start...

1

Working with a (father) template acting as a router/controller for embedded (children) templates as suggested by Peter Lewis is a perfectly fine approach in some cases. A classical use case would be to have the same template used for lists and detail views.

However, in that case, have a look at switchee and ifelse by Mark Croxton. These will allow you to work with complex conditional logic without having EE parse each and every chunk of code or embed inside those conditionals. Big performance gain.

If you want to aim even higher, you could also look at Stash and the template partial approach. The learning curve is a lot steeper but the benefits can be huge. Here is a good article by Trevor Davis over at Viget.

3
  • Just a note that embeds are not subject to the 'advanced conditional trap' (where the innards of advanced conditional sections are fully processed before being filtered). Any embeds inside advanced conditional sections that do not apply will not be processed. Sep 28, 2013 at 10:07
  • sure about that one? Didn't know that ... learning every day. Oct 7, 2013 at 7:46
  • fairly sure yep - haven't tested recently though. Embeds instantiate a whole new run-through of the template parser and are parsed after advanced conditionals: loweblog.com/downloads/ee-parse-order.pdf Oct 7, 2013 at 11:32
0

You may want to look at the Pages module that ships with EE. It will let you define custom URLs and also select which template to use for specific entries.

It does, however, break out of the standard EE URL structure which is important to understand if you're building with EE.

Your Answer

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

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