Skip to content
Newer
Older
100644 42 lines (29 sloc) 1.22 KB
26fa0d4 @lukaszb Added documentation for jinja2 extension - refs issue #92
lukaszb authored Sep 13, 2011
1 Jinja2 Support
2 ==============
3
4 Django Compressor comes with support for Jinja2_ via an extension.
5
6 Plain Jinja2
7 ------------
8
9 In order to use Django Compressor's Jinja2 extension we would need to pass
10 ``compressor.contrib.jinja2ext.CompressorExtension`` into environment::
11
12 import jinja2
13 from compressor.contrib.jinja2ext import CompressorExtension
14
15 env = jinja2.environment(extensions=[CompressorExtension])
16
17 From now on, you can use same code you'd normally use within Django templates::
18
19 from django.conf import settings
20 template = env.from_string('\n'.join([
21 '{% compress css %}',
22 '<link rel="stylesheet" href="{{ STATIC_URL }}css/one.css" type="text/css" charset="utf-8">',
23 '{% endcompress %}',
24 ]))
25 template.render({'STATIC_URL': settings.STATIC_URL})
26
27 For coffin users
28 ----------------
29
30 Coffin_ makes it very easy to include additional Jinja2_ extensions as it
31 only requires to add extension to ``JINJA2_EXTENSIONS`` at main settings
32 module::
33
34 JINJA2_EXTENSIONS = [
1bd8252 @voidfiles Jinja2 expects a reference to a class, not a module.
voidfiles authored Oct 28, 2011
35 'compressor.contrib.jinja2ext.CompressorExtension',
26fa0d4 @lukaszb Added documentation for jinja2 extension - refs issue #92
lukaszb authored Sep 13, 2011
36 ]
37
38 And that's it - our extension is loaded and ready to be used.
39
40 .. _Jinja2: http://jinja.pocoo.org/docs/
41 .. _Coffin: http://pypi.python.org/pypi/Coffin
Something went wrong with that request. Please try again.