DOM Helper¶
dom_id¶
dom_id is a helper method that returns a unique DOM ID based on the object’s class name and ID
{% load turbo_helper %}
{% dom_id instance %} -> task_1
{% dom_id instance 'detail' %} -> detail_task_1
{% dom_id Task %} -> new_task
dom_idfirst argument can be string, instance or Model classdom_idsecond argument is optional string that will be used asprefix.The
dom_idcan help make the id generation behavior consistent across the project, and save our time to update it inturbo-streamorturbo-frameelement.You can also use it in your Django view code.
Use in Django view
from turbo_helper import dom_id
target = dom_id(instance, "detail_container")
class_names¶
Inspired by JS classnames and Rails class_names
class_names can help conditionally render css classes
<div class="{% class_names test1=True 'test2' ring-slate-900/5=True already-sign-in=request.user.is_authenticated %}"></div>
'<div class="test1 test2 ring-slate-900/5 dark:bg-slate-800 %}"></div>'
It can also work well with TailwindCSS’s some special css char such as / and :