1

I have a site that will heavily rely on the structure entry type to allow the client to publish content.

The "1st" level of the structure will always act as a table of contents for its children. The child pages will always contain the actual content (supplied via a matrix field).

- Page A (TOC)
    - Page B (Content)
    - Page C (Content)
        - Page D (Content)
- Page E (TOC)
    - Page F (Content)
    - Page G (Content)
- Page H (TOC)
    - Page I (Content)
- ...

This means that the fields visible in the control panel for level 1 entries need to be different to the fields for level 2 + entries.

Is it possible to have conditional fields based on the structure's level?

  • I notice I can set up different "entry types" for sections which would allow the user to select the fields they want to use. This could be done via a "Content" entry type and "Table of contents" entry type, although not automatically – Timmy O'Mahony Feb 27 at 13:46
2

This is not possible natively to have conditional fields based on the structure's level. For the same cases as yours, I'm also using different entry types.

Maybe you could consider moving your children to a Channel and link them to their parent using an Entry field + some routing, or using one of the plugins bellow to add a bit of hack, but I would not recommend it at all:

|improve this answer|||||
  • Thanks. I had a feeling this would be the case. I was thinking that I could possibly create a plugin that automates the level > entry type mapping via JavaScript, but I'm not sure it's possible to know what level a structure entry is before it's been saved, so that might not make sense. – Timmy O'Mahony Feb 27 at 15:31
  • 1
    You can get the current level in JS if you inspect the value of #parentId > .elements > [data-level]. To add custom JS scripts in the CP, you could use this plugin: plugins.craftcms.com/cp-js – Romain Poirier Feb 27 at 15:36

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.