statamic / ideas

đŸ’¡Discussions on ideas and feature requests for Statamic
https://statamic.dev
30 stars 1 forks source link

Pass context (such as blueprint/collection names) in CP so it can be used in conditions #1070

Open benfurfie opened 8 months ago

benfurfie commented 8 months ago

Problem

When building websites in Statamic, a common pattern is to create fieldsets that can be reused by blueprints across the site, for example, heroes. However, sometimes it's necessary to add a new field that is only used in a smaller subset of the blueprints it's implemented on.

While it could be added to the blueprint after the fieldset, this doesn't always make sense from a UX perspecitve. For example, if you have an intro field, and you also need a short_intro field for use on card previews, it doesnt make sense if the short_intro field is potentially four or five fields below.

For example, let's say you have pages and articles collections, and only the articles collection needs the short_intro field, it isn't possible to hide it on the pages entry page, and it's redundant (that or you end up with duplicate fieldsets). This can confuse users, or worse, prevent the use of validation like required, sometimes to ensure users are filling it out.

Proposed solution

Statamic already has a potential solution to this problem; conditional rendering of fields. The issue is that currently the only fields that can be used to conditionally render are ones that are present in the blueprint itself. This means that data that is in the context isn't available to conditionally render.

Attemped Workarounds

I've tried adding a hidden or read_only field to blueprints with the name of the blueprint, and using this to conditionally render a field within a fieldset pulled in, but this doesn't work. However, it does if it's in the blueprint itself, but this completely defeats the object.