EEConf 2024 is around the corner! EEConf 2024
The scenario is as follows. I will be creating episode guides for two or more TV shows. I already have an existing setup where there’s an Episodes template group and an Episodes channel, but that’s for one show. To accommodate additional shows, I am looking at two options but I am not sure which is the most optimal.
1) Stay with the existing setup. Episodes for the new show(s) get added to the same channel as before (existing categories get moved to a parent category named Show A and a parent category Show B with new sub categories is added). The same Episodes template group is used for displaying the content.
With this approach, I don’t yet know how to accomplish a display division between Show A and Show B. The idea is that Show A and Show B would each get a static page as an index which links through to show-specific content (in addition to Episodes, there’ll also be Characters). But if they are sharing a template group for Episodes, can this be accomplished? For example, could I use this kind of URL: www.domain.com/ShowA/Episodes/ where “ShowA” is an added segment that tells the Episodes template to only display content from the ShowA category and to use only the fields relevant for ShowA (there will be some differences regarding which fields each show uses).
2) Option two is to, at minimum, rework the template group setup. I would create one template group called ShowA and one called ShowB and in each of those there would be templates called Episodes. The downside is that with each new show I need additional template groups and templates. This option could possibly also involve creating a separate Channel for Episodes for each show, which would make it easier to allow variations in the fields used by each show without needing conditionals in the templates.
To start with how things are organized in the back-end:
I would have a channel — call it “shows” — with an appropriate field group, which stores everything for the shows themselves. Each entry would be a single show. One of the fields in this channel would be a relationship field to a second channel:
The second channel — call it “episodes” — would store everything that was specific to each episode. Each entry would be a single episode.
A lot depends on how much information you’re storing for shows, episodes, characters, etc. But you might also have a third channel — call it “characters” — which would store everything that was specific to each character. Each entry would be a single character. You could then have a relationship field in the “episodes” channel which pointed to the “characters” channel, so that you’d have a record of which chararacters appeared in which episodes.
I’d do all of this first, before you start thinking about templates, etc. Get the data structures working the way you want, and the rest follows.
Thanks Paul! I am not quite following the need for the “Shows” channel, could you explain that a little further? Right now, the plan is that a character guide and an episode guide is the only information for each show. The current setup (which was created when there was only one show to cover) has quite a lot of fields in both the character guide and the episodes guide, so I don’t think episodes and characters could easily share a channel. There is basically a current data structure, but I am uncertain whether it is worth changing it or not.
If you’re planning on growing this — which it sounds like you are — it’s probably worth looking at what will work best when there’s a lot more of everything: shows, episodes, characters, etc.
My thought was that the “Shows” channel would have two jobs:
— Store all of the information that’s about the show itself, rather than any individual characters or episodes. So, things like: a general synopsis, when it started, ended, whatever information you have/want that’s global to the whole show. An entry for each show.
— Link, using relationship fields, to other channels, for information about individual episodes, characters, etc.
So, imagine you have a template which displays all of the information about a single show. It would use the relevant entry in the “Shows” channel to display the general information about the show. It would then use the relationship field in this entry which points to the “Episodes” channel to access the episodes information for the show.
Without knowing exactly what information you have, and how sophisticated you want to be, it’s hard to know exactly what structure would be best, but the idea of having separate channels for shows, episodes, and characters (maybe widening to “People” if you want to include crew as well as cast), and then using relationship fields to link them together, sounds like it’s a good way to go.
Ah, ok, then I understand. In a sense I am both growing and reducing at the same time, because while I am making room for more shows, I am reducing the amount of information about each. Still, the idea of using a Shows channel for relationships is intriguing (I do have relationship fields between Episodes and Characters already).
However, I am still not certain which template setup would be most convenient going forward. I think I would like to continue with a template group called Characters and one called Episodes (each having their own templates for lists of characters or episodes and for single entries), but I am not sure about the best approach to be able to provide a URL that lists Show A episodes and a URL that lists Show B episodes?
Honestly, I think having a “Shows” channel solves most of your issues here. Your URLs might then work like:
— /show (triggers a template which grabs the entry from the “Shows” channel)
— /show/episode (triggers a template which grabs the show entry from the “Shows” channel, and uses the relationship field to grab the entry for the episode from the “Episodes” channel.)
— /show/character (triggers an entry which grabs the show entry from the “Shows” channel, and uses a relationship field to grab the entry for the character from the “Characters” channel.)
Why go through the “Shows” entry in the second and third cases? Because you might have the same episode titles in different shows, and the same character names in different shows.
I am playing around with this approach now. There’s a couple of drawbacks to using relationships that I am not sure can be worked around (I haven’t used them a lot so could be missing something).
1) Let’s say that when triggering — /show I want to display the introductory information about the show plus a list of all episodes and all characters. With relationships, it looks like I am stuck with ordering them alphabetically or in order of when the entries were created. Alphabetically works for characters, but episodes I would have preferred to order by season and number.
2) When adding relationships, I don’t suppose there is any way to filter so I only see those episodes and characters that aren’t already assigned to another show?
> 1) Let’s say that when triggering — /show I want to display the introductory information about the show plus a list of all episodes and all characters. With relationships, it looks like I am stuck with ordering them alphabetically or in order of when the entries were created. Alphabetically works for characters, but episodes I would have preferred to order by season and number.
You should be able to do that. You can use most of the same parameters in the relationship tag that you can in the channel entries tag. So, if you have a series # field and an episode # field in each episode entry, you can use the orderby
parameter to sort by series/episode. You can even have something like orderby=series_num | episode_num
, so it groups by series, and then within each series by episode.
> 2) When adding relationships, I don’t suppose there is any way to filter so I only see those episodes and characters that aren’t already assigned to another show?
No, I don’t think so.
> Did you envision a single template group called “show” or one for each show named for the show?
A single template (or template group), which would work for all of the shows. It can get the show name from the URL, and then pull up the relevant entry from the “Shows” channel. So, once you have the templates you need, all you’d be doing after that would be adding new entries.
> You should be able to do that. You can use most of the same parameters in the relationship tag that you can in the channel entries tag. So, if you have a series # field and an episode # field in each episode entry, you can use the orderby parameter to sort by series/episode. You can even have something like orderby=series_num | episode_num, so it groups by series, and then within each series by episode.
Thanks, I will give that a try. Should be able to get there with some trial and error I think!
>A single template (or template group), which would work for all of the shows. It can get the show name from the URL, and then pull up the relevant entry from the “Shows” channel. So, once you have the templates you need, all you’d be doing after that would be adding new entries.
This one is stumping me a bit. I’ve gone with a “shows” template group and I am using the “index” template for the show entries. Ideally I’d like to display the intro page for a show on the url -/shows/name_of_show, but right now it wants -/shows/index/name_of_show. Any way to work around that other than an .htaccess rewrite? I am not quite used to doing single-entry pages like that, so I may be missing something.
> This one is stumping me a bit. I’ve gone with a “shows” template group and I am using the “index” template for the show entries. Ideally I’d like to display the intro page for a show on the url -/shows/name_of_show, but right now it wants -/shows/index/name_of_show. Any way to work around that other than an .htaccess rewrite? I am not quite used to doing single-entry pages like that, so I may be missing something.
There are other ways, but I like using template routes for this sort of thing. They’re just a way of telling EE which URLs trigger which templates. Because a template route can include variables, you can use it to match a range of URLs to a single template.
If you give your shows/index
template this template route (in the Access tab):
/shows/{name-of-show:alpha_dash}
it’ll trigger for any URL with two segments, where the first segment is “shows”. The second segment here is a variable, name-of-show
.
Then, in the shows/index
template, you’ll use a channel entry tag which looks something like:
{exp:channel:entries channel="shows" status="Open" url_title="{segment:name-of-show}" dynamic="no"}
This grabs the URL segment called name-of-show
, and uses it to select the entry in the shows
channel with that url title.
(Make sure to include dynamic="no"
, which stops EE from trying to guess which template you need, and just uses the one you’ve specified in the route.)
> — /show (triggers a template which grabs the entry from the “Shows” channel)
I think I´ve got this one sorted out. Just basic formatting, but it seems to grab what it should: https://www.westeros.org/Shows/Game_of_Thrones/
> — /show/episode (triggers a template which grabs the show entry from the “Shows” channel, and uses the relationship field to grab the entry for the episode from the “Episodes” channel.)
> — /show/character (triggers an entry which grabs the show entry from the “Shows” channel, and uses a relationship field to grab the entry for the character from the “Characters” channel.)
These two I am still trying to wrap my head around. The templates should be set to fetch data from the Shows channel, but how does it know which show it is fetching data for once the show name is no longer in the URL?
> These two I am still trying to wrap my head around. The templates should be set to fetch data from the Shows channel, but how does it know which show it is fetching data for once the show name is no longer in the URL?
Sorry, my examples were way too simple there. For a single episode, I might have a URL something like:
/show/name-of-show/ep/name-of-episode
with a template route of:
/show/{name-of-show:alpha_dash}/ep/{name-of-episode:alpha_dash}
which would trigger your episode template. Within that template, you’d pull the episode entry in much the same way that you pull the show in the show template:
{exp:channel:entries channel="episodes" status="Open" url_title="{segment:name-of-episode}" dynamic="no"}
The trick is then getting the show information. Once you have the episode entry, you can grab the show entry using the relationship field. Something like:
{parents field="relationship_field"}
{parents:title}, etc.
{/parents}
where relationship_field
is the name of the relationship field in the show
channel which points to the episodes
channel. You’re going backwards here, from the child (episode) to the parent (show). So technically you don’t need the show name in the URL, because having the episode name (which has to be unique) in the URL gives you access to the show information via the relationship field. But I think having the show name in the URL is still the right thing to do. It makes your URL structure much clearer and more consistent.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.