File tree Expand file tree Collapse file tree 2 files changed +20
-5
lines changed
django_simple_bulma/templatetags Expand file tree Collapse file tree 2 files changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -102,7 +102,9 @@ theme by providing a key that matches the regex `\w+_variables` (e.g. `alt_varia
102
102
stylesheets will then be generated using the variables at that key.
103
103
104
104
To use these stylesheets in a template, pass the theme name to the ` {% bulma %} ` tag either as a
105
- string ` {% bulma 'alt' %} ` or as a template variable ` {% bulma theme %} ` .
105
+ string ` {% bulma 'alt' %} ` or as a template variable ` {% bulma theme %} ` . When calling the ` bulma ` template
106
+ more than once in the same document (for example for implementing a dark theme switch), you will want to pass ` include_js=False ` to
107
+ at least one of these to prevent duplicate loading of JavaScript resources.
106
108
107
109
#### Extensions
108
110
Original file line number Diff line number Diff line change 12
12
13
13
14
14
@register .simple_tag
15
- def bulma (theme : str = "" ) -> SafeString :
16
- """Build static files required for Bulma."""
15
+ def bulma (theme : str = "" , * , include_js : bool = True ) -> SafeString :
16
+ """Build static files required for Bulma.
17
+
18
+ Parameters:
19
+ theme:
20
+ CSS theme to load. If the given theme can not be found, a warning
21
+ will be logged and the library will fall back to the default theme.
22
+
23
+ Keyword arguments:
24
+ include_js:
25
+ Whether to include directives to load Bulma's JavaScript resources
26
+ in the result. Useful to prevent duplicate loading of JS when
27
+ calling this tag more than once on the same resource.
28
+ """
17
29
from ..utils import (
18
30
get_js_files ,
19
31
logger ,
@@ -36,8 +48,9 @@ def bulma(theme: str = "") -> SafeString:
36
48
]
37
49
38
50
# Build html to include all the js files required.
39
- for js_file in map (static , get_js_files ()):
40
- html .append (f'<script defer type="text/javascript" src="{ js_file } "></script>' )
51
+ if include_js :
52
+ for js_file in map (static , get_js_files ()):
53
+ html .append (f'<script defer type="text/javascript" src="{ js_file } "></script>' )
41
54
42
55
return mark_safe ("\n " .join (html ))
43
56
You can’t perform that action at this time.
0 commit comments