Skip to content

Commit b3ad05d

Browse files
authored
Change bootstrap_setting from filter to tag (#595)
1 parent 8c5af0e commit b3ad05d

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

src/django_bootstrap5/templates/django_bootstrap5/bootstrap5.html

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,29 @@
22
{% load django_bootstrap5 %}
33
{% load i18n %}
44
{% get_current_language as LANGUAGE_CODE %}
5+
{% bootstrap_setting 'javascript_in_head' as BOOTSTRAP_JAVASCRIPT_IN_HEAD %}
56
<html lang="{{ LANGUAGE_CODE|default:'en_us' }}">
67

78
<head>
8-
99
<!-- Required meta tags -->
1010
<meta charset="utf-8">
1111
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
12-
1312
<!-- Page title -->
1413
<title>{% block bootstrap5_title %}django-bootstrap5 template title{% endblock %}</title>
15-
1614
<!-- Bootstrap CSS -->
1715
{% bootstrap_css %}
18-
1916
<!-- Bootstrap JavaScript if it is in head -->
20-
{% if 'javascript_in_head'|bootstrap_setting %}
21-
{% bootstrap_javascript %}
22-
{% endif %}
23-
17+
{% if BOOTSTRAP_JAVASCRIPT_IN_HEAD %}{% bootstrap_javascript %}{% endif %}
2418
{% block bootstrap5_extra_head %}{% endblock %}
25-
2619
</head>
2720

2821
<body>
2922
{% block bootstrap5_before_content %}{% endblock %}
3023
{% block bootstrap5_content %} CONTENT {% endblock %}
3124
{% block bootstrap5_after_content %}{% endblock %}
32-
3325
<!-- Bootstrap JavaScript if it is in body -->
34-
{% if not 'javascript_in_head'|bootstrap_setting %}
35-
{% bootstrap_javascript %}
36-
{% endif %}
37-
26+
{% if not BOOTSTRAP_JAVASCRIPT_IN_HEAD %}{% bootstrap_javascript %}{% endif %}
3827
{% block bootstrap5_extra_script %}{% endblock %}
39-
4028
</body>
4129

4230
</html>

src/django_bootstrap5/templatetags/django_bootstrap5.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
register = template.Library()
2727

2828

29-
@register.filter
29+
@register.simple_tag
3030
def bootstrap_setting(value):
3131
"""
3232
Return django-bootstrap5 setting for use in in a template.
3333
34-
Please consider this filter private, do not use it in your own templates.
34+
Please consider this tag private, do not use it in your own templates.
3535
"""
3636
return get_bootstrap_setting(value)
3737

tests/test_bootstrap_css_and_js_tags.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,14 @@ def test_bootstrap_css_tag_with_theme(self):
4242
)
4343

4444
def test_bootstrap_setting_filter(self):
45-
self.assertEqual(self.render('{{ "required_css_class"|bootstrap_setting }}'), "django_bootstrap5-req")
4645
self.assertEqual(
47-
self.render('{% if "javascript_in_head"|bootstrap_setting %}head{% else %}body{% endif %}'), "head"
46+
self.render("{% bootstrap_setting 'required_css_class' %}"),
47+
"django_bootstrap5-req",
48+
)
49+
self.assertEqual(
50+
self.render(
51+
"{% bootstrap_setting 'javascript_in_head' as BOOTSTRAP_JAVASCRIPT_IN_HEAD %}"
52+
"{% if BOOTSTRAP_JAVASCRIPT_IN_HEAD %}head{% else %}body{% endif %}"
53+
),
54+
"head",
4855
)

0 commit comments

Comments
 (0)