lektor-website/content/docs/api/templates/globals/get-random-id/contents.lr

23 lines
501 B
Plaintext
Raw Normal View History

2015-12-19 14:52:17 +01:00
title: get_random_id
---
summary: Generates a new random ID.
---
type: function
---
template_var: get_random_id
---
body:
In some situations it can be very useful to generate a unique ID in templates.
This is particularly useful when creating templates for the [Flow
2022-02-27 18:14:05 +01:00
:ref](../../../../content/flow/) system and you need unique IDs for the DOM.
2015-12-19 14:52:17 +01:00
## Example
```html+jinja
{% set id = get_random_id() %}
<div id="{{ id }}">
<button data-target="{{ id }}" class="toggle">Hide This</button>
</div>
```