I removed the CPL and added the suffix as you suggested:
{% for p in product.metafields.custom.linked_product_list %}
P: {{ p.product.title }}
{% assign matching_count = matching_count | plus: 1 %}
{% capture output %}
{{ output }}
{% if p.product.featured_image %}
{% endif %}
{% endcapture %}
{% endfor %}
{% if matching_count > 0 %}
Colors:
{% if matching_count > 8 %}
{% endif %}
{{ output }}
{% if matching_count > 8 %}
{% endif %}
{% endif %}
But now it doesn’t show anything:
The inspect shows the outer div only:

