Created on 5 May 2021, over 3 years ago
Updated 27 September 2023, over 1 year ago

Problem/Motivation

Perhaps it would be possible to have a Twig function to add JavaScript or CSS directly in a Twig template.

Proposed Resolution

Code block tags that would add opening/closing tags. Would possibly need a way to add additional parameters for tag attributes (e.g. CSS media, script type).

{% attachinline-js %}
  alert("Hello World!");
{% endattachinline-js %}

{{ attachinline-js("alert('Hello World!');", ['attribute': 'value']) }}

or

Delimiters that need to be placed inside the tag.

<style media="all">{% attachinline-css %}
  body {
}
{% endattachinline-css %}</style>

This wouldn't work with CSP nonces, which need to add an attribute to the tag.
Whitespace is important for CSP hashes, so if not placed immediately next to wrapping tags hash value would be invalid (and would possibly need to be aware of whitespace removal (e.g. {% attachinline -%}).

✨ Feature request
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada gapple

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024