Chapter 5: Beer and Planning Time!
Developing a Data Structure
One natural next step at this point in the site build would be to start implementing EE Channels, Fields, and Category Groups to hold our content. However, before making that move, let's step back, grab a beer and think about the overall site data structure.
Due in part to EE's flexibility, the following step is often a point of confusion for many newcomers to ExpressionEngine. This is a good time to read the Category or Channel article on Train-ee. It can be found at:
[link]
In addition to the issues covered in that post, another important one for me - since I'm usually building EE-based sites for clients - is what structure is going to be most understandable for them. Let's work backwards through our main navigation and determine the requirements for each section. The potential spot for client confusion will come up as we get back to the Home and About sections:
- Contact. This will only require one template - no Channel, categories, or channel fields needed.
- Weblog. An obvious one - the Channel needs to be self-contained, needs a discreet set of categories, and will need the typical title/body/extended text data fields in a dedicated Channel Field Group. I'll also want an archive function.
- Services. Typically a Services section will have multiple entries and a specific set of categories. The field structure can be a simple title/page content structure. All in all, I think we'd be best served by creating another Channel to hold Services content, with its own Category Group and Channel Field Group.
- Products. These may align with Services by sharing the same categories, but usually the content has more fields - for price, stock #, availability, etc. Let's go with another dedicated Channel and another Channel Field Group, but look into sharing a Category Group with Services so that we can show related Products when viewing Services, and vice/versa.
- About. This is where things get a bit fuzzy. Some sites have a one-page About section, with no categories and a simple title/page content field structure. These requirements are very similar to the requirements for the Home page.
One option is a shared Channel for the Home and About sections - an approach I've used in the past. What I don't like about that was how it became an exception for content management while training the client. With dedicated channels for all other site sections, the publishing/editing process was very straightforward - clients used either the Create or Modify options on the Control Panel Home Page. Sharing a Channel for the Home and About sections added an extra step for maintaining the content in that shared Channel. - Based on that experience, I'll now go with a dedicated Channel for the About section - even if it only ever contains one post. The About section can share the same title/page content Channel Field Group as the Services section, and doesn't need categories.
- Home. Same decision as the About section - dedicated Channel, no categories, and will share a Field Group with Services and About.
So there's our data structure requirements - five Channels, two Category Groups, and three Channel Field Groups.
I usually end up adding one Channel to that structure for miscellaneous content such as site footers, "no search results" messages and 404 template content. For this site specifically, I'll use a miscellaneous content Channel to hold the paragraph to the left of the search field. I think these paragraphs would work well as section overviews or customer testimonials and I would prefer they be editable in Channel posts rather than hardcoded into templates.
Developing a Template Structure
In ExpressionEngine, content is not hard-mapped to your site's URL structure. You can essentially define how you want your site's URLs to read by how you work with EE's Template Groups and templates.
While we've got a good grip on the back-end structures needed to store our content, let's go through the process of designing a Template Group and template structure so we know what our final URLs will look like.
ExpressionEngine URLs
ExpressionEngine URLs are derived from your Template Group and template structure in the following manner:
- Template Group Index Templates:
http://mysite.com/index.php/te... - Other Templates:
http://mysite.com/index.php/te...template - Index Template in Category Mode:
http://mysite.com/index.php/te...category/category_url_title - Other Templates in Category Mode:
http://mysite.com/index.php/te...template/category/category_url_title - Template Group Index Templates showing Single Entry:
http://mysite.com/index.php/te...entry_url_title - Other Templates showing Single Entry/:
http://mysite.com/index.php/te...template/my_url_title
More on EE's URL logic can be found in the EE User Guide:
http://ellislab.com/expression...
So, how to proceed? Let's look at a couple of options.
One Big Bucket
One way would be to create one "site" Template Group and put all of the main templates in it. This approach has appeal, especially if the site is small. In our case, the site template might contain the following templates:
- index (home page)
- about
- products (products index page)
- products-list (products category view)
- products-detail (detail for one product)
- services
- services-list
- services-detail
- weblog
- weblog-comments
- contact
That's not an overwhelming number of templates, so from an organizational point of view it's not bad. But, let's look at some sample URLs this template structure will generate:
- Home Page
http://mysite.com (index) - About
http://mysite.com/index.php/site/about - Products Index
http://mysite.com/index.php/site/products - Products Category
http://mysite.com/index.php/site/products-list/category/interior - Product Detail
http://mysite.com/index.php/site/products-detail/seats - Weblog
http://mysite.com/index.php/site/weblog - Weblog Comments
http://mysite.com/index.php/site/weblog-comments
Notice anything here? I don't particularly like that /site/ segment showing in all of the URLs. It really doesn't add anything to the URL other than length.
This approach also doesn't scale as well. If I need to come back and add two or three more main sections to my site the number of templates in this one group could double or triple.
Let's take another stab at our template organization and see what then happens to the URLs.
More Buckets
Another approach would be to create Template Groups for all main content areas, and then organize our templates into those groups. For our site, we'd then have the following Template Groups and templates:
- site
- index
- stylesheet
- about
- index
- products
- index
- list
- detail
- services
- index
- list
- detail
- weblog
- index
- comments
- contact
- index
This Template Group and template structure will generate the following URLs:
- Home Page
http://mysite.com (index) - About
http://mysite.com/index.php/about - Products Index
http://mysite.com/index.php/products - Products Category
http://mysite.com/index.php/products/list/category/interior - Product Detail
http://mysite.com/index.php/products/detail/seats - Weblog
http://mysite.com/index.php/weblog - Weblog Comments
http://mysite.com/index.php/weblog/comments
These URLs look much better to me now that we've now lost the /site/ segment. In addition the deeper templates in the Products area are more semantic in their structure.
This is the template organizational structure that I'll move forward with.
Template Routes
ExpressionEngine 6 included a new feature called Template Routes. Template Routes let you map URL segments to variables and then create rules for how they are processed - essentially letting you work totally outside of the native EE url structures and create your own.
The User Guide has details on Template Routes:
[link]
Index.php Removal
EllisLab supports removing index.php entirely from your URLs. Instructions are in the EE User Guide:
[link]
For the purposes of this book I'm just going to leave index.php in place - so you'll have a clearer understanding of the generated URLs and what Template Groups and templates are being viewed.
How ExpressionEngine Thinks About Content
For more on this whole topic of structuring the backend of your ExpressionEngine projects I'd suggest taking a look at chapters 2-4 of the Building a Portfolio series on Train-ee:
[link]
In those chapters I cover how I would structure the backend of a EE build for a portfolio site, from the high-level down to a specific plan for channels, categories, and fields.
With a solid plan in place, let's move on to more implementation work.