django-unfold: Template tag/variable syntax error in `unfold/layouts/skeleton.html` in 0.56.0

What version of Unfold are you using?

0.56.0

What version of Django are you using?

5.2.0

What browser are you using?

None (Django view tests)

Did you checked changelog/commit history, if the bug is not already fixed?

Yes. Regression in version 0.56.0 I think; was just released.

Did you searched other issues, if the bug is not already fixed?

Yes

Did you checked documentation?

Yes

Are you able to replicate the bug in the demo site?

No. It’s a fairly simple bug so I hope this is enough.

Repository with reproduced bug

Just try to render the unfold/layouts/skeleton.html template.

Describe your issue

Template has a syntax error, specifically using {{% where the intent is that the first { is an opening bracket of a javascript/alpinejs object, and the {% belongs to a template tag, but the template parses interprets the {{ as a template variable.

See unfold/layouts/skeleton.html .

x-data="{{% if opts %}activeTab: 'general',{% endif %} sidebarMobileOpen: false, sidebarDesktopOpen: {% if request.session.toggle_sidebar == False %}false{% else %}true{% endif %} }"

From my test suite

FAILED anonymous_project/users/tests/test_admin.py::test_view_user - django.template.exceptions.TemplateSyntaxError: Could not parse the remainder: '% if opts %}activeTab: 'general',{% endif %} sidebarMobileOpen: false, sidebarDesktopOpen:...

I’ll open a PR directly after this.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 4
  • Comments: 15 (10 by maintainers)

Most upvoted comments

I can confirm the same fix is applied on base.tag_re by django-components : https://github.com/django-components/django-components/blob/master/src/django_components/apps.py#L56

This behavior can be disabled using settings.MULTILINE_TAGS. It is enabled by default

Hi. I don’t use django-cotton, but django-components. I forgot that djc also adds some stuff on top of the template parsing. Actually probably a lot of people use the same multiline tag parsing somewhere…

I guess that’s it, I can’t check right now, but I think it’s probably fair to say it’s not really a bug in unfold. Thanks for changing it anyway.