Zilong Li
Zilong Li

Reputation: 958

Can I have Django template tags inside a django-compressor tag?

For example:

{% compress css %}
    <link rel="stylesheet" href="{% static 'css/foo.css' %}">
    {% if foobar %}
    <link rel="stylesheet" href="{% static 'css/bar.css' %}">
    {% endif %}
{% endcompress %}

As above, can I have an if tag inside the compress tag? Does this work with the OFFLINE_COMPRESSION mode?

Upvotes: 0

Views: 156

Answers (2)

Zilong Li
Zilong Li

Reputation: 958

I tested it myself. The answer is no, as of Aug. 2018.

A workaround maybe using multiple compress tags as mentioned by in the other answer.

Upvotes: 0

Max
Max

Reputation: 1844

django-compressor docs says nothing about it. But you can use few {% compress %} tags like this:

{% compress css %}
    <link rel="stylesheet" href="{% static 'css/foo.css' %}">
{% endcompress %}
{% if foobar %}
    {% compress css %}
        <link rel="stylesheet" href="{% static 'css/bar.css' %}">
    {% endcompress %}
{% endif %}

Upvotes: 0

Related Questions