2


I am trying to make my stylesheets dynamic with django (jinja2) and I want to do something like this:

<link rel="stylesheet" href="{% static 'home/css/{{ block css }}{{ endblock }}.css' %}">

Apparently, I can't use Jinja in Jinja :), and I don't know how to make this work another way.

2
  • Why not include separate files based on conditions? Commented Jul 10, 2016 at 13:15
  • How exactly? Sorry, I am fairly new... Could you please precise ? Commented Jul 10, 2016 at 13:41

2 Answers 2

2

I found a solution that works out pretty well.

I use <link rel="stylesheet" href="{% block css %}{% endblock %}"> in the template
and then: {% block css%}{% static 'home/css/file.css' %}{% endblock % in each page

Sign up to request clarification or add additional context in comments.

Comments

-1

Couldn't you do something like this?

{% if condition == True %}
    <link rel='stylesheet' href='file1.css'>
{% else %}
    <link rel='stylesheet' href='file2.css'>
{% endif %}

And so on.

1 Comment

That would become very messy on a large scale actually ;(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.