I've got a layout_discovery template set up like this, for use in a field layout:
{% if content %}
<div{{ attributes.addClass(classes) }}>
<div class="layout-region layout-region--main col-sm-8">
{{ content.main }}
</div>
{% if content.sidebar %}
<div class="layout-region layout-region--sidebar col-sm-4">
{{ content.sidebar }}
</div>
{% endif %}
</div>
{% endif %}
(I have also tried {% if content.sidebar|trim|length > 0 %}
with no change in the result.)
A content type using this layout puts a single, optional field into the sidebar region. If that field is empty, I would expect content.sidebar to be empty, so that the sidebar div won't be output and the main div can expand to fill the space. However, instead I get an empty sidebar div:
<div class="layout-region layout-region--sidebar col-sm-4">
</div>
Is there any way to accomplish this in a field layout, or do I need to build a custom node template instead?