Add a template tag for generating a unique ID.

Review Request #14547 — Created Aug. 3, 2025 and submitted

Information

Djblets
release-5.x

Reviewers

We have many cases where we need a unique ID for the purposes of the
aria-labelledby= or aria-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
Add a template tag for generating a unique ID.
We have many cases where we need a unique ID for the purposes of the `aria-labelledby=` or `aria-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.
3d7444de408e2526717886a1f26181836a02c85c
david
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-5.x (913b195)