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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With