Entries retain field data that has been removed from entry type layout I have a single page section titled "About".  At one point, I had assigned a "text" Rich Text field to the entry type layout.  I then put some filler text in this field and saved the entry.  Later I removed this field from the field layout.

The issue is that craft still populates this entry field on the front-end, i.e. {{ entry.text }} still shows the filler text.

This is problematic for several reasons, but most importantly (in my scenario) because I am working on a search results template which shows an excerpt from each entry; different entries may have different fields available, so I am doing a basic if/else to see what fields may be available, i.e.:

{% if entry.text is defined %}
    {{ entry.text }}
{% elseif entry.multiContent.text is defined %}
    {{ entry.multiContent.text }}
{% endif %}


This raises two questions:

1) Is there a way to tell if an field is actually actively assigned to the entry layout?

2) I understand why the field data would be retained in the database even though the field was removed from the layout, but under what circumstances would populating 'deleted' fields for entries be desired behavior?  It surely adds overhead, it is counter-intuitive (imo) and has the potential to cause all sort of issues.
Technically, all entries have all fields, regardless of their layout. Field layouts are mostly just a UI thing.


  1) Is there a way to tell if an field is actually actively assigned to the entry layout?


It’s a little cumbersome and would require the MN Break and Continue plugin, but yes:

{% for flf in entry.getFieldLayout().getFields() %}
    {% set field = flf.getField() %}

    {% if field.handle == 'text' %}
        {{ entry.text }}
        {% break %}
    {% elseif field.handle == 'multiContent' %}
        {{ entry.multiContent.text }}
        {% break %}
    {% endif %}
{% endfor %}



  2) I understand why the field data would be retained in the database even though the field was removed from the layout, but under what circumstances would populating 'deleted' fields for entries be desired behavior? It surely adds overhead, it is counter-intuitive (imo) and has the potential to cause all sort of issues.


Actually it’s faster for Craft to not worry about the field layout, which is why it’s not taken into account right now. Less data to fetch, and logic to run. If you check for entry.text, Craft just assumes you know what you’re doing.

Maybe a better approach would be to just check the entry type’s ID/name:

{% if entry.typeId in [1,2,3] %}
    {{ entry.text }}
{% elseif entry.typeId in [4,5,6] %}
    {{ entry.multiContent.text }}
{% endif %}


(or)

{% if entry.type.handle in ['one', 'two', 'three'] %}
    {{ entry.text }}
{% elseif entry.type.handle in ['four', 'five', 'six'] %}
    {{ entry.multiContent.text }}
{% endif %}