File tree Expand file tree Collapse file tree 3 files changed +14
-19
lines changed
templates/django_bootstrap5 Expand file tree Collapse file tree 3 files changed +14
-19
lines changed Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 2626register = template .Library ()
2727
2828
29- @register .filter
29+ @register .simple_tag
3030def 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
Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments