1

I am trying to create a site that offers courses. Each course will be broken up into sections with each sections containing a number of lessons. Viewers will then be able to progress through the course one lesson at a time - at their own pace (like Lynda.com).

Note: the sections are merely there for organizational purposes - they don't actually house any content. All the actual content is limited to the Course page and the individual Lessons.

I am trying to figure out the best way to organize this. This is my current thinking (but I'm not sure this is the best way to do it).

Section & Entry Types

I have created a Structure Section called Courses with two Entry Types:

  • Course
  • Lesson

I have then set up a matrix field for the Course entry type with two field types:

  • Section Name: Plain Text field type for the name of the section
  • Section Lessons: Entries field type set to Courses (for the list of lessons in each section)

The idea being that on the course page I could quickly and easily create a number of sections and then add the relevant lessons to each section. I can then set up the template to progress through each section and it's lessons in order.

With that said, I had two other ideas.

Set up three entry types - Course, Section & Lesson

I would then have the Course be the parents of the various Sections and the Sections be the parents of the various Lessons.

This also seems fairly easy to do (the only problem is creating an entry for each section given that the Sections don't actually house any content).

Set up categories for each course

I could then assign each lesson to a category (I would then have to figure out how to order the content).

Any suggestions as to which is the best way to proceed?

Thanks.

1

Short answer: I'd lean towards a structure section. Matrix is a close second.

Long answer: When I'm faced with this an information architecture decision, I look at a couple things:

  • How "reusable" is the solution? (is content only stored in one place?)
  • Is it easy for the content author?

What's great about Craft is it generally makes both relatively easy. What you don't want is to duplicate content in more than one section because it creates multiple sources of truth.

  • I typically reach for Matrix fields when I need to mix/match content on a single page.
  • Entries/Structures are better when you need to build content that could potentially be brought in from any area of the site.

  • Categories are usually "global" in scope. They also wouldn't be the right choice here. You'd end up creating too many of them and you'd eventually want to create a category set for each course to keep everything straight.

Matrix

Let's look at the workflow for doing it the Matrix way. If you want to create a new lesson, you need to define it in two places: the Lesson entry itself and the Section/divider entry (and then tell Craft which section the Lesson entry goes).

It's also going to be harder to see from the CP how many lessons are in the section.

I find Matrix fields tougher to template as well. If you use Matrix for navigation, you're going to have to iterate over all of them to see which one you're currently on. Because you're relating the entry, you're also going to have to do a "reverse" lookup.

Structures

That said, Structures bring their own set of problems and solutions. I like structures because you can easily move them up and down in the hierarchy. If a content author messed up and put a lesson in the wrong section, it's an easy drag/drop.

I also find templating a bit easier too. Want to get your current section you're in? Just get its parent:

{% set courseSection = entry.parent %}

Then you can spit out its children:

<ul>
{% nav %}
  <li> <a href="{{ entry.url }}">{{ entry.title }}</a></li>
{% endnav %}
</ul>

URLs

When you create a parent/child relationship in a structure section, the parent is going to create a new URL as well. That might not be ideal if you have thin content in the divider like you mentioned.

So your URL might look like this:

Course / Section / Lesson url.com/craft-cms/twig/intro-to-twig

If you use a Matrix field:

Course / Lesson url.com/craft-cms/intro-to-twig

That "thin" content is going to live at twig for example. I don't necessarily see that as bad thing but keep that in mind.

Although you might not use the section/divider for much content now, you may end up needing it in the future. Every slug in that course has to be unique now as well because you're not dividing it up. You wouldn't be able to do this with a matrix field:

Course / Section / Lesson url.com/craft-cms/twig/intro url.com/craft-cms/twig/filters

If you use a Matrix field, it would have to be something like:

Course / Lesson url.com/craft-cms/intro-to-twig url.com/craft-cms/twig-filters

That's a little harder to keep consistent from a content authoring perspective as well.

I see it as a "table of contents" for the section. In a traditional book, it might be an introduction to what you're about to learn in each section. Otherwise you'd need to create another lesson called "Introduction" for example.

So to sum it up, a structure with 3 entry types is what I'd use followed by Matrix. I don't think could go wrong with either solution though.

  • Wow -- what a great answer. Extremely helpful. I'm going to give the Structure option a try as it seems to make more sense for the various reasons you laid out. Thanks. – Moshe Mar 7 '17 at 14:29
  • Thank you! The best thing about Craft is there's a lot of different ways to do it. You might find one option works better than the other. – RitterKnight Mar 8 '17 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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