Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Compressor inline removes custom attributes

I'm using Django compressor for Static resources. How ever while trying to compress an inline style tag, it removes custom attributes from style tag that I need for some other stuff

Code :

{% compress css inline %}
    <style some-custom-attribute type="text/css">
        *{
              padding:0px;
              margin:0px;
        }
    </style>
{% endcompress css %}

output

<style type="text/css">*{padding:0px;margin:0px}</style>

expected result

<style some-custom-attribute type="text/css">*{padding:0px;margin:0px}</style>
like image 660
sandiprb Avatar asked May 22 '26 21:05

sandiprb


1 Answers

The solution is partially explained in https://github.com/django-compressor/django-compressor/issues/690:

In one of your apps (make sure it is above compressor in your INSTALLED_APPS setting), create a file in the template folder compressor/css_inline.html to override it.

In that template you can set the content to something like

<style type="text/css"{% if compressed.media %} media="{{ compressed.media }}"{% endif %} some-custom-attribute>{{ compressed.content|safe }}</style>

Note that this solution is rather hackish and will affect all compressed inline css output. You might be able to make it more dynamic by writing a custom context processor.

like image 141
Joren Avatar answered May 25 '26 11:05

Joren