Reputation: 8276
I have a web app where users can have profiles (somewhat like facebook) and they can view their own profile as well as other peoples profiles. What you would see in your own profile would be everything, but someone else viewing your profile might not be able to see everything on it.
In order to accomplish this, I have common-profile.html and profile.html where profile.html includes common-profile.html and common-profile.html is what everyone can see. So if I want to view my own profile I would see profile.html but someone else would see common-profile.html.
The problem is that when I use template inheritance, both of those templates inherit from some base template so the template gets imported twice.
profile.html:
{% extends 'base.html' %}
{% block content %}
{% include 'common-profile.html' %}
...other stuff would go here
{% endblock %}
common-profile.html:
{% extends 'base.html' %}
{% block content %}
<h1>{{c_user.first_name}} {{c_user.last_name}}<h1>
...other stuff would go here
{% endblock %}
Is this just a bad idea? Should I just have one profile and check permissions/use some if statements in template tags? I don't want to have too much logic in my html pages but if it's just some if statements to decide what to show, maybe that's ok?
Upvotes: 2
Views: 1831
Reputation: 526563
What about instead of using an include, you made profile.html
extend common-profile.html
? Then just have an empty block in the common profile template that the non-common-profile template can add stuff to. Something like this:
{% extends 'base.html' %}
{% block content %}
<!-- Normal common profile stuff -->
{% block extendedcontent %}{% endblock extendedcontent %}
{% endblock content %}
{% extends 'common-profile.html' %}
{% block extendedcontent %}
<!-- Special profile stuff -->
{% endblock extendedcontent %}
Upvotes: 6