Login

SASS/SCSS include template tag.

Author:
bryanhelmig
Posted:
February 7, 2012
Language:
Python
Version:
1.3
Tags:
template tag tags scss sass
Score:
0 (after 0 ratings)

You'll need to pip install pyScss first.

Converts on the fly, so you won't want to use this for much more than just testing.

Usage in a template:

{% load sass %}

{% include_sass "disclosures/css/base.scss" %}
{% include_sass "disclosures/css/grid.scss" %}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
from django.template import Node
from django.template.base import Library
from django.template.loader_tags import do_include

from scss import Scss
sass = Scss()

register = Library()

class SASSNode(Node):
    def __init__(self, node):
        self.node = node

    def render(self, context):
        raw = self.node.render(context)
        return sass.compile(str(raw))

def sass_include(parser, token):
    return SASSNode(do_include(parser, token))

register.tag('include_sass', sass_include)

More like this

  1. Create variables within templates by nkwenti 6 years, 11 months ago
  2. whitespaceoptimize block tag by peterbe 6 years, 8 months ago
  3. Severity codes in user messages by cconnell 6 years, 4 months ago
  4. Custom CSS class in Form with template tag filter by kegan 5 years, 11 months ago
  5. Add CSS class template filter by lazerscience 4 years, 6 months ago

Comments

Please login first before commenting.