einen ähnlichen Anwendungsfall hatte ich mal in einem Projekt (... das Projekt ist leider nicht mehr öffentlich zugänglich)
Schau mal, ob du hiermit dein Auslangen findest.
Soweit ich mich aber erinnern kann, hat das auch Einfluss auf die anderen angelegten Akkordeons, sodass ich das dann projektweit gleich direkt über die /templates/content_element/accordion.html.twig laufen liess.
PHP-Code:
{% extends "@Contao/content_element/accordion.html.twig" %}
{% block script %}
{% add "handorgel_js" to body %}
{% set script_attributes = attrs()
.setIfExists('nonce', csp_nonce('script-src'))
.mergeWith(script_attributes|default)
%}
<script src="{{ asset('js/handorgel.min.js', 'contao-components/handorgel') }}"></script>
<script{{ script_attributes }}>
(function () {
const instances = [];
document.querySelectorAll('.content-accordion').forEach((el) => {
const acc = new handorgel(el, {
{% block init_options %}
multiSelectable: false,
{# Put custom options here #}
{% endblock %}
});
instances.push(acc);
acc.on('fold:open', () => {
instances.forEach((other) => {
if (other === acc) return;
other.folds.forEach((f) => f.close());
});
});
});
})();
</script>
{% endadd %}
{% endblock %}