How to deal with brackets that are no tokens

Created on 23 May 2025, 11 days ago

Problem/Motivation

I have a "Render: twig" action which includes an inline Javascript snippet. I know that may not look like best practice, however sometimes quick and simple solutions are needed.

The included inline JS looks like this:

<script>
document.querySelector('[name="my_field"]').addEventListener('change', e => {
    const u = new URL(window.location);
    u.searchParams.set('my_field', e.target.value);
    window.location.href = u;
  });
</script>

The problem is that the produced output of the template looks like this:

<script>
document.querySelector('').addEventListener('change', e => {
    const u = new URL(window.location);
    u.searchParams.set('my_field', e.target.value);
    window.location.href = u;
  });
</script>

The query selector argument was interpreted as token and got replaced by an empty string.

What's the best way to deal with this?

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

💬 Support request
Status

Active

Version

3.0

Component

Miscellaneous

Created by

🇩🇪Germany mxh Offenburg

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

Comments & Activities

Production build 0.71.5 2024