How do you check if a template is included into another?

6 views
Skip to first unread message

Luna Tuna

unread,
Jan 5, 2018, 3:03:39 PM1/5/18
to Django users
Say I have a content editing template with a simple text area and title field.   Then I'll need a publish button for it of course.

But if I include this conten editor in a larger template, the position of the publish button will go to the bottom of additionally included content,

so I only want to render the publish button in the first template if I know that content_edit.hml is not included in a larger template.

How would I accomplish this?

Julio Biason

unread,
Jan 5, 2018, 3:13:09 PM1/5/18
to django...@googlegroups.com
Hi Luna,

Why not do something like:

Have a base template that you will use for the basic editing, let's call it `base_content_edit.html`:

{% extends whatever-you-use-as-base-template %}

{% block editor %}
<textarea></textarea>
{% endblock %}
<button>

and then, when you need a rich editor, you have a new template, say `rich_content_edit.html`:

{% extend "base_content_edit" %}

{% block editor %}
<rich-content-editor></rich-content-editor>
{% endblock %}


Django templates are more based on the building on top of previous content than including bits and pieces (although you can do that with no issues).

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ddb6d351-113d-4ff7-ba12-602a9a12a6a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Julio Biason, Sofware Engineer
AZION  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101  |  Mobile: +55 51 99907 0554
Reply all
Reply to author
Forward
0 new messages