Add a template tag for generating a unique ID.
Review Request #14547 — Created Aug. 3, 2025 and submitted
We have many cases where we need a unique ID for the purposes of the
aria-labelledby=
oraria-describedby=
attribute. In some cases, it's
a bit burdensome to have to come up with an ID, as templates are
sometimes generated dynamically based on iterating over other content.This introduces a
{% unique_id %}
template tag that takes in a prefix
and outputs that prefix followed by an auto-incremented ID. It works
much like Underscore.js/Lodash's_.uniqueId()
. function.IDs are only unique if precautions are taken. It can't know how the ID
will be used or what else may be on the page. However, it won't generate
the same ID across different calls on the same template render.
Unit tests passed.
Made use of this in some in-progress code.
Summary | ID |
---|---|
3d7444de408e2526717886a1f26181836a02c85c |