// controller.php
$scripts[] = [
...
'integrity' => ($integrity) ? sprintf(' integrity="%s"', $integrity) : null,
],
// view.twig
{% for script in scripts %}
<script type="text/javascript" id="{{ script.code }}-js" src="{{ script.src }}"{{ script.integrity|raw }} crossorigin="anonymous"></script>
{% endfor %}