Re: Suggestion for improvement to template block/extends tags
Russ his solution is better indeed, but the content of the middle block has to be defined in the child template, so it would become the following: a.html {% block decorated %}first {% block content %}{% endblock %} last{% endblock %} b.html {% extends a.html %} {% block decorated %}left {{ block.super }} right{% endblock %} template.html {% extends (either "base.a.html" or "base_b.html") %} {% block content %}middle{% endblock %} Off topic: The {% decorate %} template tag has its uses, but is indeed not required here. It is a design pattern that's commonly used in languages like XAML.net. It is more readable and compact than the only current alternative: including a template and using {% extends %} inside the include. cheers, Jonathan -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
Re: Suggestion for improvement to template block/extends tags
Hi Russ. {% decorate (either "a.html" or "b.html") %} This isn't actual syntax; it's just trying to communicate that the subtemplate (not the base), can extend either a.html or b.html. It would be implemented by {% decorate base_template %}, where base_template is a context variable. This is commonly done with the {% extends %} tag already. The base template is absolutely not referencing the names of the templates that descend from it; that would be silly as you point out. On May 3, 10:25 am, Russell Keith-Mageewrote: > On Fri, Apr 29, 2011 at 4:48 PM, Jonathan Slenders > > > > > > > > > > wrote: > > Hey, this pattern are nested decorators in templates. > > > Most people here are probably against having nested template tags with > > the same name. I think it does only make sense when there's somehow a > > distinction between a > > "placeholder" and "content". Because otherwise, templates don't know > > which block in the parent template need to be chosen when several have > > the same name. (You'd say the most inner block, but that's not obvious > > -- I think.) > > > I once wrote a {% decorate %} template tag for a little similar > > behaviour. > >https://github.com/citylive/django-template-tags/blob/master/src/djan... > > > That would become: > > > template.html: > > {% decorate (either "a.html" or "b.html") %} > > middle > > {% enddecorate %} > > > b.html: > > {% decorate "a.html" %} > > left {{ decorator.content }} right > > {% enddecorate %} > > > a.html: > > first {{ decorator.content }} last > > > Hope that helps. > > I once tried to get this into django trunk, but did not yet got > > accepted. > > For me, this: > > > {% decorate (either "a.html" or "b.html") %} > > is enough of a reason to reject this proposal -- I fundamentally have > no idea what this is trying to say, or why it's trying to say it this > way. Why does a base template need to reference the names of the > templates that descend from it? For me, this is completely bass > ackwards. > > I'm also slightly confused as to why your proposal isn't already covered by: > > template.html > {% block decorated %} > middle > {% endblock %} > > a.html > {% extends template.html %} > {% block decorated %}left {{ block.super }} right{% endblock %} > > b.html > {% extends template.html %} > {% block decorated %}first {{ block.super }} last{% endblock %} This isn't the problem I'm trying to solve. template.html extends from a.html / b.html, not the other way around. My original post shows that the problem is different to this, I think. > > Yours, > Russ Magee %-) Thanks for checking this out :) -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
Re: Suggestion for improvement to template block/extends tags
On Fri, Apr 29, 2011 at 4:48 PM, Jonathan Slenderswrote: > Hey, this pattern are nested decorators in templates. > > Most people here are probably against having nested template tags with > the same name. I think it does only make sense when there's somehow a > distinction between a > "placeholder" and "content". Because otherwise, templates don't know > which block in the parent template need to be chosen when several have > the same name. (You'd say the most inner block, but that's not obvious > -- I think.) > > I once wrote a {% decorate %} template tag for a little similar > behaviour. > https://github.com/citylive/django-template-tags/blob/master/src/django_template_tags/templatetags/decorate.py > > That would become: > > template.html: > {% decorate (either "a.html" or "b.html") %} > middle > {% enddecorate %} > > > b.html: > {% decorate "a.html" %} > left {{ decorator.content }} right > {% enddecorate %} > > a.html: > first {{ decorator.content }} last > > Hope that helps. > I once tried to get this into django trunk, but did not yet got > accepted. For me, this: > {% decorate (either "a.html" or "b.html") %} is enough of a reason to reject this proposal -- I fundamentally have no idea what this is trying to say, or why it's trying to say it this way. Why does a base template need to reference the names of the templates that descend from it? For me, this is completely bass ackwards. I'm also slightly confused as to why your proposal isn't already covered by: template.html {% block decorated %} middle {% endblock %} a.html {% extends template.html %} {% block decorated %}left {{ block.super }} right{% endblock %} b.html {% extends template.html %} {% block decorated %}first {{ block.super }} last{% endblock %} Yours, Russ Magee %-) -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
Re: Suggestion for improvement to template block/extends tags
Thanks for this; I'll check out your "decorate" tag. On Apr 29, 6:48 pm, Jonathan Slenderswrote: > Hey, this pattern are nested decorators in templates. > > Most people here are probably against having nested template tags with > the same name. I think it does only make sense when there's somehow a > distinction between a > "placeholder" and "content". Because otherwise, templates don't know > which block in the parent template need to be chosen when several have > the same name. (You'd say the most inner block, but that's not obvious > -- I think.) I probably haven't thought it through completely, but _if_ nested blocks were allowed, I can't see any other interpretation of their use. If I have a base template: {% block content %}left {% block content %}{% endblock %} right{% endblock %} And I extend that and override {% block content %}, any other interpretation would make the inner block useless. > > I once wrote a {% decorate %} template tag for a little similar > behaviour.https://github.com/citylive/django-template-tags/blob/master/src/djan... > > That would become: > > template.html: > {% decorate (either "a.html" or "b.html") %} > middle > {% enddecorate %} > > b.html: > {% decorate "a.html" %} > left {{ decorator.content }} right > {% enddecorate %} > > a.html: > first {{ decorator.content }} last > > Hope that helps. > I once tried to get this into django trunk, but did not yet got > accepted. > > On 29 avr, 02:11, amagee wrote: > > > > > > > > > I sometimes run into a situation where I want a template to be able to > > extend from one of a set of possible base templates, which I achieve > > by passing a "base_template" variable in the context to the {% extends > > %} tag. Where this gets stuck, though, is if one of the possible > > bases extends one of the other possible bases. > > > For example: > > > base_a.html: > > first {% block content %}{% endblock %} last > > > base_b.html > > {% extends "base_a.html" %} > > {% block content %}left {% ??? %} right{% endblock %} > > > template.html > > {% extends (either "base.a.html" or "base_b.html") %} > > {% block content %}middle{% endblock %} > > > I'd like to be able to code template.html so that if it extends > > base_a.html, the result is "first middle last", but if it extends > > "base_b.html", the result is "first left middle right last". > > > I _think_ it would make sense to implement this with an improvement to > > the semantics of the {% block %} tag, starting by allowing nested tags > > with the same name. > > > If base_b.html were: > > {% extends "base_a.html" %} > > {% block content %}left {% block content %}{% endblock %} right{% > > endblock %} > > > Then the {% block content %} in template.html could override the > > _inner_ block in base_b.html. I think this behaviour is pretty > > logical and consistent, unless I've missed something. I've hacked > > around a bit with loader_tags.py but I'm finding it quite difficult to > > get what I want with my limited understanding of how it works. > > > Do people think this idea makes sense? Is it worth taking the time to > > write a patch for it? -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
Re: Suggestion for improvement to template block/extends tags
Yes, I'm using something similar to that now; it works, but it's not as elegant as I'd like. On Apr 29, 10:19 am, legutierrwrote: > Hi amagee- > > Have you tried this? > > base_a.html > first {% block content %}{% block subcontent %}{% endblock %}{% > endblock%} last > > base_b.html > {% extends "base_a.html %} > {% block content %}left{% block subcontent %}{% endblock %}right{% > endblock %} > > template.html > {% extends (either "base.a.html" or "base_b.html") %} > {% block subcontent %}middle{% endblock %} > > On Apr 28, 8:11 pm, amagee wrote: > > > > > > > > > I sometimes run into a situation where I want a template to be able to > > extend from one of a set of possible base templates, which I achieve > > by passing a "base_template" variable in the context to the {% extends > > %} tag. Where this gets stuck, though, is if one of the possible > > bases extends one of the other possible bases. > > > For example: > > > base_a.html: > > first {% block content %}{% endblock %} last > > > base_b.html > > {% extends "base_a.html" %} > > {% block content %}left {% ??? %} right{% endblock %} > > > template.html > > {% extends (either "base.a.html" or "base_b.html") %} > > {% block content %}middle{% endblock %} > > > I'd like to be able to code template.html so that if it extends > > base_a.html, the result is "first middle last", but if it extends > > "base_b.html", the result is "first left middle right last". > > > I _think_ it would make sense to implement this with an improvement to > > the semantics of the {% block %} tag, starting by allowing nested tags > > with the same name. > > > If base_b.html were: > > {% extends "base_a.html" %} > > {% block content %}left {% block content %}{% endblock %} right{% > > endblock %} > > > Then the {% block content %} in template.html could override the > > _inner_ block in base_b.html. I think this behaviour is pretty > > logical and consistent, unless I've missed something. I've hacked > > around a bit with loader_tags.py but I'm finding it quite difficult to > > get what I want with my limited understanding of how it works. > > > Do people think this idea makes sense? Is it worth taking the time to > > write a patch for it? -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
Re: Suggestion for improvement to template block/extends tags
Hey, this pattern are nested decorators in templates. Most people here are probably against having nested template tags with the same name. I think it does only make sense when there's somehow a distinction between a "placeholder" and "content". Because otherwise, templates don't know which block in the parent template need to be chosen when several have the same name. (You'd say the most inner block, but that's not obvious -- I think.) I once wrote a {% decorate %} template tag for a little similar behaviour. https://github.com/citylive/django-template-tags/blob/master/src/django_template_tags/templatetags/decorate.py That would become: template.html: {% decorate (either "a.html" or "b.html") %} middle {% enddecorate %} b.html: {% decorate "a.html" %} left {{ decorator.content }} right {% enddecorate %} a.html: first {{ decorator.content }} last Hope that helps. I once tried to get this into django trunk, but did not yet got accepted. On 29 avr, 02:11, amageewrote: > I sometimes run into a situation where I want a template to be able to > extend from one of a set of possible base templates, which I achieve > by passing a "base_template" variable in the context to the {% extends > %} tag. Where this gets stuck, though, is if one of the possible > bases extends one of the other possible bases. > > For example: > > base_a.html: > first {% block content %}{% endblock %} last > > base_b.html > {% extends "base_a.html" %} > {% block content %}left {% ??? %} right{% endblock %} > > template.html > {% extends (either "base.a.html" or "base_b.html") %} > {% block content %}middle{% endblock %} > > I'd like to be able to code template.html so that if it extends > base_a.html, the result is "first middle last", but if it extends > "base_b.html", the result is "first left middle right last". > > I _think_ it would make sense to implement this with an improvement to > the semantics of the {% block %} tag, starting by allowing nested tags > with the same name. > > If base_b.html were: > {% extends "base_a.html" %} > {% block content %}left {% block content %}{% endblock %} right{% > endblock %} > > Then the {% block content %} in template.html could override the > _inner_ block in base_b.html. I think this behaviour is pretty > logical and consistent, unless I've missed something. I've hacked > around a bit with loader_tags.py but I'm finding it quite difficult to > get what I want with my limited understanding of how it works. > > Do people think this idea makes sense? Is it worth taking the time to > write a patch for it? -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
Re: Suggestion for improvement to template block/extends tags
Hi amagee- Have you tried this? base_a.html first {% block content %}{% block subcontent %}{% endblock %}{% endblock%} last base_b.html {% extends "base_a.html %} {% block content %}left{% block subcontent %}{% endblock %}right{% endblock %} template.html {% extends (either "base.a.html" or "base_b.html") %} {% block subcontent %}middle{% endblock %} On Apr 28, 8:11 pm, amageewrote: > I sometimes run into a situation where I want a template to be able to > extend from one of a set of possible base templates, which I achieve > by passing a "base_template" variable in the context to the {% extends > %} tag. Where this gets stuck, though, is if one of the possible > bases extends one of the other possible bases. > > For example: > > base_a.html: > first {% block content %}{% endblock %} last > > base_b.html > {% extends "base_a.html" %} > {% block content %}left {% ??? %} right{% endblock %} > > template.html > {% extends (either "base.a.html" or "base_b.html") %} > {% block content %}middle{% endblock %} > > I'd like to be able to code template.html so that if it extends > base_a.html, the result is "first middle last", but if it extends > "base_b.html", the result is "first left middle right last". > > I _think_ it would make sense to implement this with an improvement to > the semantics of the {% block %} tag, starting by allowing nested tags > with the same name. > > If base_b.html were: > {% extends "base_a.html" %} > {% block content %}left {% block content %}{% endblock %} right{% > endblock %} > > Then the {% block content %} in template.html could override the > _inner_ block in base_b.html. I think this behaviour is pretty > logical and consistent, unless I've missed something. I've hacked > around a bit with loader_tags.py but I'm finding it quite difficult to > get what I want with my limited understanding of how it works. > > Do people think this idea makes sense? Is it worth taking the time to > write a patch for it? -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
Suggestion for improvement to template block/extends tags
I sometimes run into a situation where I want a template to be able to extend from one of a set of possible base templates, which I achieve by passing a "base_template" variable in the context to the {% extends %} tag. Where this gets stuck, though, is if one of the possible bases extends one of the other possible bases. For example: base_a.html: first {% block content %}{% endblock %} last base_b.html {% extends "base_a.html" %} {% block content %}left {% ??? %} right{% endblock %} template.html {% extends (either "base.a.html" or "base_b.html") %} {% block content %}middle{% endblock %} I'd like to be able to code template.html so that if it extends base_a.html, the result is "first middle last", but if it extends "base_b.html", the result is "first left middle right last". I _think_ it would make sense to implement this with an improvement to the semantics of the {% block %} tag, starting by allowing nested tags with the same name. If base_b.html were: {% extends "base_a.html" %} {% block content %}left {% block content %}{% endblock %} right{% endblock %} Then the {% block content %} in template.html could override the _inner_ block in base_b.html. I think this behaviour is pretty logical and consistent, unless I've missed something. I've hacked around a bit with loader_tags.py but I'm finding it quite difficult to get what I want with my limited understanding of how it works. Do people think this idea makes sense? Is it worth taking the time to write a patch for it? -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.