templates block prepend and append

412 views
Skip to first unread message

Mateusz Harasymczuk

unread,
May 20, 2011, 12:14:30 PM5/20/11
to django-d...@googlegroups.com
I have recently fought with extending templates.
Plenty of my usecases are almost the same: append some html before or after admin templates blocks.

To do so, I have to take template, copy the contents and save modified file as a html in my templates dir.

What happens if django contrib.admin pages gets an update?
I have to take templates and do my job once again.

I suggest adding templatetag

- {% prepend "blockname" %}{% endprepend %}
- {% append "blockname" %}{% endappend %}

or "before/after" blocks

or even modification to extends

{% extends "admin/index.html" "after" "blockname" %}

What do you think?


--
Matt Harasymczuk

Luke Plant

unread,
May 20, 2011, 12:36:38 PM5/20/11
to django-d...@googlegroups.com
On 20/05/11 17:14, Mateusz Harasymczuk wrote:
> I have recently fought with extending templates.
> Plenty of my usecases are almost the same: append some html before or
> after admin templates blocks.

{{ block.super }} sounds like what you want. If not, please let us know why.

Regards,

Luke

--
The early bird gets the worm, but the second mouse gets the cheese.
--Steven Wright

Luke Plant || http://lukeplant.me.uk/

Mateusz Harasymczuk

unread,
May 20, 2011, 12:50:22 PM5/20/11
to django-d...@googlegroups.com
This should solve my problems, therefore my question is no longer valid.

I missed that in the documentation.

Probably I should ask at django-users first.

Although

{% extends "admin/index.html" after "blockname" %}

would be a nice shorthand.

or 

{% from "admin/index.html" import "blockname" %}

to import only one block from a template file.

Amin Jun

unread,
Aug 24, 2015, 2:07:04 PM8/24/15
to Django developers (Contributions to Django itself)
I liked his suggestion, I don't know if I'm using template tags correctly, but I'm writing a template tag {% load_comment comment_manager %} ,
"load_comment" renders a file "comments.html" and also needs a file "comment.js" and in any page that has comments, I have to add "comment.js" manually to my {% block js %}.
it was better if i could put something like this in my "comments.html" file

{% append_block js %}
< script src="..." ></script>
{% end_append_block %}
 
Best regards

Jun

Collin Anderson

unread,
Aug 24, 2015, 4:38:24 PM8/24/15
to django-d...@googlegroups.com
Hi Jun,

I think this might do what you want:

{% block js %}{{ block.super }} <script src="..."></script> {% endblock %}

But, like the original poster said, please use django-users list for things like this.

Thanks,
Collin


--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/3e77b96d-c187-406a-8d08-140958dac251%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Shai Berger

unread,
Aug 24, 2015, 5:07:45 PM8/24/15
to django-d...@googlegroups.com
Hi and all,

On Monday 24 August 2015 23:37:57 Collin Anderson wrote:
> On Mon, Aug 24, 2015 at 2:25 AM, Amin Jun <mohammad.a...@gmail.com>
>
> wrote:
> > I liked his suggestion, I don't know if I'm using template tags
> > correctly, but I'm writing a template tag {% load_comment
> > comment_manager %} , "load_comment" renders a file "comments.html" and
> > also needs a file "comment.js" and in any page that has comments, I have
> > to add "comment.js" manually to my {% block js %}.
> > it was better if i could put something like this in my "comments.html"
> > file
> >
> > {% append_block js %}
> > < script src="..." ></script>
> > {% end_append_block %}
> >
>
> I think this might do what you want:
>
> {% block js %}{{ block.super }} <script src="..."></script> {% endblock %}
>

I think it does not -- this, as he complained, needs to be put manually in
every page which uses his {% load_comment %} tag; IIUC, he's asking for a way
for his tag to do that for him.

I'm not sure that such a mechanism is feasible or even sensible within DTL,
but it's a valid issue for this list, unless I'm missing something.

Shai.
Reply all
Reply to author
Forward
0 new messages