csp_hash - Twig Function
Info
This feature is available in Contao 5.3 and later.
This allows you to add CSP hashes for inline styles and scripts.
{# Generate the hash for some inline JavaScript #}
{% set script %}
alert('foo');
{% endset %}
<script>{{ script }}</script>
{% do csp_hash('script-src', script) %}
{# Generate the hash for some inline styles #}
{% set style %}
body {
background-color: magenta;
}
{% endset %}
<style>{{ style }}</style>
{% do csp_hash('style-src', style) %}
Arguments
directive
: The CSP directive the hash will be generated for.source
: The content for whith the hash will be generated for.algorithm
: You can optionally define the hashing algorithm (default issha256
).