1

I have two structures: Focus Areas & Initiatives.

I'd like to be able to associate the two of these structures. Here's a potential example:

Focus Areas:

  • Sports
  • Music
  • Art

Initiatives:

  • Basketball
  • Soccer
  • Trumpet
  • Painting

My organization has a number of Initiatives, each fit under a certain Focus Area.

On each Focus Area page, I would like to show all Initiatives associated. Currently, for each Initiative, I have a Radio Button for each Focus Area it fits under, but am having trouble thinking of how to further narrow down entries to show from the example below (which shows all initiatives):

{% set entries = craft.entries.section('initiatives') %}
{% for entry in entries %}
    {{entry.title}}
{% endfor %}

Would this be an appropriate use case for Categories? Should I instead be using Entry Types for each Focus area?

3

There are a number of ways to organize this using any combination of channels, structures, or categories — it's hard to give a recommendation on which way is better without knowing a little more about your site requirements.

Much will depend on things like:

  • Will there be pages for both 'focus-areas' and 'initiatives' (or is one just used for organization)?
  • How the uri's should look? (i.e. 'focus-area/initiative/' or '/focus-areas/focus-area/' & '/initiatives/initiative')
  • Are the relationships 'one-to-one' or 'many-to-one'?
  • Are the pages hierarchical and/or need a specific order defined?
  • Do the pages need entryTypes (because the layout and/or field requirements are unique for different pages)?
  • Do you need to generate site-navigation dynamically?

Answering these questions will generally narrow down the options.

On each Focus Area page, I would like to show all Initiatives associated. Currently, for each Initiative, I have a Radio Button for each Focus Area it fits under.

Typically, instead of a radioButton, you would create a relationship between any two channels/structures/categories using the EntriesFieldType. Once you have added the field to your focus-areas field layout, and added some related initiative entries, you can access the related initiatives using:

{% for initiative in entry.initiatives %}
    <li>{{ initiative.title }}</li>
{% endfor %}

or

{% set initiatives = craft.entries.section('initiatives').relatedTo(entry) %}
{% for initiative in initiatives %}
    <li>{{ initiative.title }}</li>
{% endfor %}

Would this be an appropriate use case for Categories?

Maybe. If you want to conceptually consider them as categories (and categories fit all your other needs) then go for it. Otherwise the difference between categories and structures/channels is pretty minor (with the exception that categories do not support entryTypes).

Should I instead be using Entry Types for each Focus area?

Maybe. EntryTypes are generally used when the field and/or layout requirements are unique in some way for the various entries. If the relationship between 'focus-areas' and 'initiatives' is one-to-one, and if you want the uri's to be 'focus-area/initiative' then a good option might be to combine the two structures together hierarchically and use EntryTypes to define the unique layout and fields requirements for each. In your template you would then check the entry's type and change the layout or include a sub-template.

{% if entry.type = "initiative" %}
    {% include '_initiative.html' %}
{% endif %}

You can also use this approach site-wide to generate more dynamic site navigation, using craft's nav tag.

| improve this answer | |
  • Thanks for the detailed answer! There's a focus areas page that lists all focus areas (3). There's an initiatives page that lists all initiatives. The URI's would look like '/focus-areas/sports' where I would say a little about sports, then pull in the sports initiatives (basketball etc). Focus Areas will have many initiatives, initiatives will have one focus area. No specific order is needed. I don't need to generate site-nav dynamically. Pages don't necessarily need entryTypes, all focus areas have one template, all initiatives have one template. Does this change your opinion at all? – Nick Apr 21 '15 at 21:33
  • I don't need a URL like 'focus-areas/sports/basketball' I can just have a link to the basketball initiative. ('initiatives/basketball'). I was trying to separate the two of these, but looking back now and reading your answer, it almost seems like would make sense to combine these structures and have something like 'focus-areas/sports/basketball' though may be too late for this. – Nick Apr 21 '15 at 21:40
  • None of your requirements would restrict you to using one solution over another. So it will mainly just come down to your preference, and how you want the CP to be organized (or how you see the site requirements changing over time). You could either combine them into one structure, if you want the initiatives nicely organized by focus area; or keep them separate, so that you don't have to deal with EntryTypes (which can add some minor complexity on the template side). I'm a fan of structures and entry types personally, but completely up to you. – Douglas McDonald Apr 21 '15 at 22:24
3

It sounds like Focus Areas could logically be a category and Initiatives a structure. They work very similarly with a few differences.

Categories can use their own template and routing which is handy. You can also associate as many fields as you want with them just like Entries so you could flesh out a category page with headings, rich-text, matrix fields, etc.

When you are on a Focus Area page, Craft will automatically set a category variable to use when the URL matches the category route just like it sets an entry variable on entry URLs.

For example, on the http://example.com/focus-area/sports page, you could use {{ category.title }} that would give you the output Sports.

On a category page, you can use the relatedTo parameter to find Initiatives entries related to that category like this:

{% set entries = craft.entries.section('initiatives').relatedTo(category) %}
{% for entry in entries %}
    {{entry.title}}
{% endfor %}

The other option that may make sense would be to make everything one nested Structure since it looks like Initiatives are exclusive to only one Focus Group.

  • Sports
    • Basketball
    • Soccer
  • Music
    • Trumpet
  • Art
    • Painting

The potential drawback is that they're in the same section so they will use the same template routing. You could use Entry Types to manage different content for Focus Areas and Initiatives. You can't however force an Entry Type to be used like level 1 entries need to be entry type X and level 2 entry type Y. So someone could accidentally set up "Trumpet" as a Focus Area.

To get a list of Initiative from a Focus Group page you could use the descendantOf parameter.

{% set entries = craft.entries.section('mySection').descendantOf(entry) %}

You could also the type parameter if you want to filter only certain Entry Types.

{% set entries = craft.entries.section('mySection').type('initiatives').descendantOf(entry) %}
| improve this answer | |

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.