﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
33469	Make ID argument of json_script filter optional	Adam Johnson	nobody	"Currently the `json_script` filter requires an ID. This is burdensome in loops, as one then has to unique ID's, perhaps in the view.

{{{
def charts(request):
    data_sets = ...
    charts = [
        {""id"": f""chart-data-{i}"", ""data"": data}
        for i, data in enumerate(data_sets)
    ]
   return render(request, ""charts.html"", {""charts"": charts})
}}}

…and use them in the template:

{{{
{% for chart in charts %}
    <my-chart data-id=""{{ chart.id }}"">
      {{ chart.data|json_script:chart.id }}
    </my-chart>
  {% endfor %}
}}}

If `json_script` did not need an ID, this work could be saved. The `<script>` tag could avoid having an `id` attribute, and JavaScript could still look up the `<script>` tag based on its position in the DOM, with e.g. `this.element.querySelect(""script[type='application/json']"")`.

The template could then be simpler, and no view logic would be required:

{{{
{% for chart in charts %}
    <my-chart>
      {{ chart.data|json_script }}
    </my-chart>
  {% endfor %}
}}}
"	New feature	closed	Template system	dev	Normal	duplicate			Unreviewed	0	0	0	0	0	0
