1

I set up a structure for pages that looks like this:

- All Services
  - Service 1
    - Service 1 subpage a
    - Service 1 subpage b
  - Service 2
    - Service 2 subpage a
    - Service 2 subpage b

I followed the accepted answer to this question to set up different templates within that structure, so now the level 2 pages (i.e. Service 1 and 2) use a different template than the level 3 subpages (i.e. a and b).

These templates have different elements, so now I want to show different fields/field layouts when I edit the page entries. For example, if I'm editing a level 2 page, it should show fields for the title, a rich text field, an image upload field, and a few other fields I've created, but if I'm editing a level 3 page, it should only show a title and rich text field.

Is it possible to do this? If not, what's the best way to handle this type of thing in Craft? I'm trying to avoid creating one structure for level 2 pages, and another structure for level 3 pages, because I'm not sure how to preserve the hierarchical relationship between level 3 and level 2 pages if I do that.

2

The only way to do this is to create multiple entry types for your structure section.

Each entry type has its own field layout (can have different fields from the other entry types in that section).

Sadly, it's not possible to restrict entry types to a particular level in a structure – i.e. if you create "Landing Page" and "Sub Page" entry types, there's no way in Craft to make sure that the level 1 and level 2 entries actually use those entry types, according to their level. So, ideally you should a) make sure whoever edits the content in that section makes sure that they should be careful to use particular entry types for particular structure levels, and b) design and create templates that are flexible enough to work even if, for example, somebody publishes a "Sub Page" entry at level 1.

Most likely, you should change your current templating setup with something like this, if you go down this route.

| improve this answer | |
  • Thanks for the info. It's unfortunate templates can't be selected on a per entry basis rather than by structure. I'll have to do as you suggested - create multiple entry types. – JacobWeiss Jun 27 at 22:37
  • I'll check it out, thank you =) – JacobWeiss Jun 30 at 23:44

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.