Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support kebab casing in vite_asset template tag #128

Conversation

kierangillblueberry
Copy link
Contributor

Attributes can be set on the entry script tag by using the following syntax:

{% vite_asset '<path to your asset>' foo="bar" hello="world" %}

However, this does not allow for kebab-cased attributes. We are using a framework that requires we set the data attribute data-turbo-track="reload" on the entry <script />.

Since kebab-cased attributes cannot be supported via kwargs, vite_asset has been updated to support JSON encoded attributes:

from django.utils.safestring import SafeString

def your_view(request):
  json_encoded_attributes = json.dumps({
    "some-item": "3",
    "some-other-item": "value",
  })

  render(request, template, context={ "json_encoded_attributes": SafeString(json_encoded_attributes) })
{% vite_asset '<path to your asset>' json_encoded_attributes=json_encoded_attributes %}

Closes #127

@kierangillblueberry kierangillblueberry changed the title support kebab casing support kebab casing in vite_asset template tag Mar 13, 2024
@Niicck
Copy link
Collaborator

Niicck commented Apr 7, 2024

This is a great feature idea! I made a PR that expands on it -- we should convert underscore_cased attributes to kebab-case automatically.

See: #131

Thank you for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow kebab-case attributes when loading vite_asset
2 participants