1

I'm trying to figure out what the best way of handling multiple pages (e.g. listing pages that list articles, events, etc) that use the same template but have different content (e.g. title, description, image, which entries it pulls).

Example:

  • News Listing Page [listing template] - displays news article list
  • Events Listing Page [listing template] - displays events list
  • Industry Events Listing Page [listing template] - displays industry events list

With each listing page having a unique title, description, etc as well.

Should I be structuring the single template file with if statements that determine which content should be loading in? (e.g. conditionals for all three in one template). What if the "unique" content needs to be editable, should all pages that use the same template be in a unique channel? All template-x pages in channel x, all template-y pages in channel y, with channel fields for each directly related to what appears on their respective templates?

I've been looking into Structure but not sure if it'll do what I'm after, or rather simplify the "big picture" in terms of site structure.

I come from a WordPress background so still trying to wrap my head around the EE way of doing things, so any help/advice/suggestions are appreciated. If my question is unclear as well let me know and I can try to re-phrase my question/what I'm after.

2
  • There is no "best way" It depends on many factors including but not limited to: Sep 6, 2013 at 23:15
  • site size / plans for scalability / # users / user experience / etc. More info would help. Sep 6, 2013 at 23:22

4 Answers 4

1

As others have pointed out, there are multiple ways to handle this in EE. And, the Partials approach mentioned by @dadonbike is generally the best, modern, architectural approach. But this may require you to make a bigger mind-shift coming from Wordpress. And it also can't be done without add-ons / it's not an approach that's native to EE (which actually is a comment on EE, rather than this approach--but it's worth mentioning).

A simpler approach is to use conditionals to display different chunks of the template, depending on the context as determined by the URL segments. And, a variation on this is to keep each context's template separate, but embed (include) each template conditionally into a master index file. Here's an example (that's a blog/index template):

{if segment_2 == ""}
    {!-- MAIN PAGE --}
    {embed="blog/.mainblog"}
{if:elseif segment_2 == "category" AND segment_3 != ""}
    {!-- CATEGORY PAGE --}
    {embed="blog/.category"}
{if:elseif segment_3 !=""}
    {!-- ARCHIVE PAGE --}
    {embed="blog/.archive"}
{if:else}
    {!-- PERMALINK PAGE --}
    {embed="blog/.permalink"}
{/if}

Because these are URL-driven approaches, in your case, if News and Events really warrant their own URLs structures, then that's a natural reason to not combine them into a single set of conditions.

Generally, if your conditionals start getting unwieldily, you'll wish you'd split things into separate templates. But, the flip-side of more separation is often duplication, where you have very similar or the same code copied in multiple templates.

So, the Partials approach does a great job of cleaning-up / removing conditionals and letting you reuse the same layout code across contexts.

But, to the degree you can live with your set of conditionals and/or repeated code across multiple files, this conditional approach totally works, is native to EE, and is something you can quickly whip out, conceptually and practically.


Also, it's totally fine in EE to have things like News and Events in separate channels, even if they are very similarly structured content. Very different content structures usually warrant different channels, but it's also OK to separate content based on user access requirements, ease of finding things in the control panel, how you want to structure your templates, and other kinds of content "filtering" you might do in your templates.

Alternatively, you could have a News & Events combined channel--e.g., using separate categories or a field to determine which item is news vs events.

Whatever approach you use, there are trade-offs. EE's biggest selling point, imho, is that it provides a bunch of parts you can put together different ways to match your content. But EE's options do mean that you always have multiple choices, that you need to think about this architectural kind of stuff, that there's usually no truly right way to do things, and that you'll probably kick yourself at least once per project for choosing one way over another. But, in the end, you'll make it work :-).

4
  • Thanks for the useful information! Few additional questions for you though:
    – Graham
    Sep 8, 2013 at 8:48
  • (Goofed and forgot to add the rest before hitting enter, added more but went past the 5 minute edit window) Assuming the whole master index approach, how would you tackle say one "listing" template at news/listing and one at events/listing with different content? It seems you would suggest combining stuff whenever possible? Or would I end up having two separate "listing" templates with duplication of code in return for separation (the more I read your post seems to imply this, but want to confirm I'm on the right train of thought).
    – Graham
    Sep 8, 2013 at 8:56
  • Furthermore, how would you handle the client being able to edit content between different "listing" templates in terms of page description, etc. Assuming I have things split up into different listing templates with replicated code for the most part, would using something like low variables/global variables be the best approach (channels seem overkill)?
    – Graham
    Sep 8, 2013 at 8:57
  • @Graham it depends what is different. If they're basically exactly the same, you could do an embed with the channel name--something like: {embed="include/.listing" section="news"} and {embed="include/.listing" section="events"}. Then, you'd use {exp:channel:entries channel="{embed:section}" ...} in the embedded template. Or, if there are more differences, you could have two separate templates, but common blocks of code in snippets or variables.
    – Jay F
    Sep 9, 2013 at 20:58
1

Graham!

I'm gonna try to help you.

You can use one template to multiple content, but I don't know if it worth the effort. Sometimes it does, but not always.

On EECMS, every directory of templates is the first segment of a variable. I, personally, use every template for two types of contents:

  • the list of all content in that channel;
  • a unique entry on that channel;

In your case, you can have three directories of files:

  • news;
  • events;
  • industry;

At the index.html of every directory, you can handle its content.

If you don't mind, try to forget about wordpress for some time. The first thing you need to do is to organize your content. Try to forget about one single field to all the content. Open your notepad and list every little piece of info every channel needs.

For your news, everything looks easy:

  • news_content;
  • news_gallery;

Just two fields.

The events are a little harder:

  • event_place;
  • event_description;
  • event_date;
  • contact_info;

Different field_groups for different kinds of content.

Just after this, you can start thinking about templates.

This is a really long discussion and I don't know if this is the better place for it.

0

Here's some reading for you. This is an advanced form of the usual template use. If you don't grasp it, thats fine. At least you know its available. partials. The main benefit is that you build one layout template( or more ) and each of your listing types (news, events and industry) tip content into it.

0

Here's the Structure add-on method. I'll try to keep it simple. With this method you'll only need two templates.

  1. Create a channel for your static pages. Let's call that channel Pages.

  2. Create your three unique listing channels: Events, News, Industry Events

  3. Create a template for the Pages channel entries which will serve as your listing view. Let's make the template pages/index. It will pull from the Pages channel, of course:

    {exp:channel:entries channel="pages" ...}
    
  4. Create your detail/article template, let's say pages/article. Set it up to read the URL to know which listing channel it will display. (I'll explain this more below in #7.)

    {exp:channel:entries channel="{segment_1}" ...}
    
  5. In Structure's settings, manage the Pages channel as a page and assign the pages/index template to it. Then create your actual pages (new entries) from within the Pages channel for Events, News, and Industry News. Make sure the Structure Page URL matches its respective listing channel's short name so you can use the segment_1 idea from #3 above. To be clear, the Events channel and Events page should have events as the short name and URL, respectively.

  6. In Structure's settings again, set the three listing channels to be managed by Structure as listing channels and assign each of them to the pages/article template.

  7. This next step is important. Now, you can go and edit each of the Pages (News, Events, Industry Events) to be related to their respective listing channel. For example, in the Events page's Structure tab, you can assign the Event channel as the "Listing Channel." Once you do that, every Event entry will have a URL of /news/article-url

I hope that's clear. This is a very common method for building EE site's. Clients like to use Structure because it provides a great UI for adding/editing pages.

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.