[Uhm, this top-posting business plus bad HTML quoting makes replying more
laborious than necessary.]
>> [snip]
> Gary Reynolds wrote:
>> lets say I have a template I want to provide called foo.html, which
>> might look like this:
>> In you application you want to just change the title block. YouIt's definitely me being thick, but it took a while to understand what
>> wouldn't be able to do this:
>>
>> {% extends "foo.html" %}
>> {% block title %}G'day, {{ request.user.username }}{% endblock %}
>>
>> due to the circular nature of this definition.
you meant by "circular nature". It's that this template fragment is going
to be put in a file also named "foo.html", right? It seems obvious after
realizing it, but for some reason it took a while. :-)
How about using a more meaningful prefix or suffix, like "def_foo.html"
>> So instead in the library we actually provide two templates. The
>> first snippet above would infact reside in _foo.html and then
>> foo.html would contain nothing more than:
>>
>> {% extends "_foo.html" %}
or "foo_def.html" or "orig_foo.html" or "foo_orig.html" or
"mezz_foo.html" or "foo_mezz.html"?
It's a general principle, so you need to document it once, and apply it
Stephen McDonald wrote:
> Would really love to hear others' opinions on this change. It
> technically makes sense to me, and it's technically quite simple, but
> feels very large and sweeping due to touching all of the templates.
only where needed: maybe not all templates need to be split this way, and
there are some that are not going to ever be overridden (famous last
words :-) ).
--
Nicola Larosa - http://www.tekNico.net/
Everywhere they go, women are being told over and over again, "You are
not good enough. You do not match up. You are flawed." Now remember,
this is key - telling women that they are flawed is key to capitalism.
- Gail Dines, December 2011
Btw, what is the policy on this mailing list? top or bottom responses?
On 5 May 2012, at 10:12, Stephen McDonald wrote:
> On Sat, May 5, 2012 at 6:55 PM, Nicola Larosa <nicola...@gmail.com> wrote:
>> [Uhm, this top-posting business plus bad HTML quoting makes replying more
>> laborious than necessary.]
> [snip]
>Aaaah, right, now I get it, took a while. For me, as a newbie to both django and mezzanine, and avid programmer, it did not shock me that foo.html would extend foo.html, as it somehow registered in my mind that these were different files, they sit in different places anyway, but I do understand that it could get confusing.
>> It's definitely me being thick, but it took a while to understand what
>> you meant by "circular nature". It's that this template fragment is going
>> to be put in a file also named "foo.html", right? It seems obvious after
>> realizing it, but for some reason it took a while. :-)
>>
> This is what I was referring to as the extra mental step. I had to think about the structure for a bit before it clicked, but once it did it makes sense. I guess what I was getting at is how many people will this happen for, and how big a step is it really. It'll vary across people I guess.
I'd cast my humble newbie vote for mezz_foo.html, if you were to decide to go the prefix route.
> How about using a more meaningful prefix or suffix, like "def_foo.html"
> or "foo_def.html" or "orig_foo.html" or "foo_orig.html" or
> "mezz_foo.html" or "foo_mezz.html"?
(and yes, it does sound like a tedious job to change it all to mezz_xxx.html everywhere; maybe worth dividing tasks to people? I volunteer, but I'd understand if you'd rather involve more expert volunteers :) ..)
Have a great weekend!
Etienne
It's definitely me being thick, but it took a while to understand whatyou meant by "circular nature". It's that this template fragment is goingto be put in a file also named "foo.html", right? It seems obvious afterrealizing it, but for some reason it took a while. :-)
This is what I was referring to as the extra mental step. I had to think about the structure for a bit before it clicked, but once it did it makes sense. I guess what I was getting at is how many people will this happen for, and how big a step is it really. It'll vary across people I guess.
It will definitely need to be in the docs. Perhaps in the FAQs: "What's with all the templates prefixed with underscores?"
Aaaah, right, now I get it, took a while. For me, as a newbie to both django and mezzanine, and avid programmer, it did not shock me that foo.html would extend foo.html, as it somehow registered in my mind that these were different files, they sit in different places anyway, but I do understand that it could get confusing.
It's a general principle, so you need to document it once, and apply itonly where needed: maybe not all templates need to be split this way, andthere are some that are not going to ever be overridden (famous lastwords :-) ).
I was a bit put off too by this being applied to every single template. There's something to be said for consistency though I guess.
How about using a more meaningful prefix or suffix, like "def_foo.html"or "foo_def.html" or "orig_foo.html" or "foo_orig.html" or"mezz_foo.html" or "foo_mezz.html"?
I've seen the underscores before in other apps, so I think it's as close to a standard as there is. Maybe base_blah.html
How would this affect the experience of the collecttemplates command? Needs a lot of thought. If we only copy blah.html (not _blah.html) then the developer gets an almost empty file. If we copy _blah.html then they lose the notion of being able to use blah.html extending _blah.html - if we give them both then it may be overkill, eg: "what are all these extra files? I only want one for each template".
And here's a crazy idea: what if we extend and replace Django's extend tag with our own that allows for circular references. I may be missing something, but taking a look at the source for extends, it doesn't seem like it would be too hard. So if page.html extends page.html, we just ensure that the physical path of the extending template isn't searched for when looking for the version to extend from. It might not even be possible.
The information that django-debug-toolbar Templates panel provides would form great basis for this. Particularly the template and context that is made available.And here's a crazy idea: what if we extend and replace Django's extend tag with our own that allows for circular references. I may be missing something, but taking a look at the source for extends, it doesn't seem like it would be too hard. So if page.html extends page.html, we just ensure that the physical path of the extending template isn't searched for when looking for the version to extend from. It might not even be possible.From my earlier attempts at this in another project, I don't think it is possible - from https://docs.djangoproject.com/en/1.3/topics/templates/#template-inheritance
- If you use {% extends %} in a template, it must be the first template tag in that template. Template inheritance won't work, otherwise.
I'm glad we've got some lively discussion on the topic anyway, looking forward to more.
Gary
You could put anything you wanted in there because there would be no circular import (extending mezzanine/index.html rather than index.html). If you didn't create your own index.html it wouldn't matter because the middleware would make it so that Django looked for index.html and mezzanine/index.html
You would also be free to create an index.html and not extend mezzanine/index.html because index.html would come before mezzanine/index.html in the template search.
I got the idea for this based on the way django allows you to override admin templates on a per app basis :What do you guys think? I think this preserves all the power of Gary's idea without making things more confusing.
Move all templates, in mezzanine, to a directory called mezzanine. So instead of index.html and pages/page.html etc... we would have mezzanine/index.html and mezzanine/pages/page.html etc...
Josh Cartmell <joshc...@gmail.com> wrote:
>So it took me a few minutes to understad how this worked, but I agree with
>Steve that once I got it it made sense. The biggest problem I see with it
>is that it will create an entry barrier for other Django developers as it
>works differently than what you would traditionally see in a Django app.
>
>A thought I had to make extending easier without adding syntax that is not
>always easy to understand is the following:
>
>Move all templates, in mezzanine, to a directory called mezzanine. So
>instead of index.html and pages/page.html etc... we would have
>mezzanine/index.html and mezzanine/pages/page.html etc...
>
>If you were visiting the index page we would still ask Django for
>index.html (not mezzanine/index.htlm). Then in the mezzanine template
>middleware we could add mezzanine/template_name.html to the path. So first
>Django would look for index.html, then mezzanine/index.html (this would be
>similar to the way we can add specific device or host templates).
>
>If you wanted to extend index.html you would simply make a template called
>index.html that looked like this:
>
>{% extends "mezzanine/index.html" %}
>...
>your template
>...
>
>You could put anything you wanted in there because there would be no
>circular import (extending mezzanine/index.html rather than index.html).
> If you didn't create your own index.html it wouldn't matter because the
>middleware would make it so that Django looked for index.html and
>mezzanine/index.html
>
>You would also be free to create an index.html and not extend
>mezzanine/index.html because index.html would come before
>mezzanine/index.html in the template search.
>
>I got the idea for this based on the way django allows you to override
>admin templates on a per app basis :
>https://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-vs-replacing-an-admin-template
>
>What do you guys think? I think this preserves all the power of Gary's
>idea without making things more confusing.
>
>> - If you use {% extends %} in a template, it must be the first
I admit defeat =)The more I think about it adding another middleware probably wouldn't be the best solution. The only other way I can imagine my proposal working would be having every Mezzanine view add multiple template to the search path and that might be to clunky, what do you think?I have a couple of comments on the proposal (index.html and index.base.html):Does it make more sense to have the default index.html (or any template) be:{% extends "index.base.html" %}or
{% include "index.base.html" %}I think they will produce the same result but I am wondering if one is semantically more correct?
My other comment is about collecttemplates. I don't think copying both templates is a good idea as that in my mind at least partially defeats the purpose of doing this in the first place. For example if you override the main block in a template but not some other block, and then you pull in Mezzanine changes you could any updates to blocks besides main without having to modify your templates. If both templates had been copied this wouldn't be true.I think it should work so that if you ask it to copy index.html it actually makes a copy of index.base.html, renames it to index.html and adds{% extends "index.base.html" %}and leaves index.base.html's extends in place (commented out){# {% extends "whatever index.base.html extends" %} #}Then a comment should be placed directly beneath with something to the effect of:If you only want to override specific blocks use the first extends and leave only those blocks you want to override. If you want to completely override the template use the second extends (or none) and do whatever you want. Feel free to delete this comment and the extends you are not using.
I think the collecttemplates command is quite useful and having it do something like I outlined would help people understand this new template inheritance and why they should use it. I think including both extends would help people know their options and do exactly what they want (similar to the multiple commented out home page options in the default projects urls). Does anyone else have thoughts on this, or how they imagine collecttemplates working?On Sun, May 6, 2012 at 1:12 AM, Stephen McDonald <st...@jupo.org> wrote:Yeah I'd like to avoid middleware for this if possible.On Sun, May 6, 2012 at 6:10 PM, Gary Reynolds <gary.r...@touchtechnology.com.au> wrote:
I think page.base.html is okay as a compromise (although I think base.base.html looks bit funny!). My strongest objection for any of the alternatives would be with prefixing the path; I think it's important that the templates reside alongside each other.I'd be against adding a middleware, we don't need to complicate it any more when it can be done easily using nothing more than "traditional" inheritance with a less-traditional hierarchy to provide greater template flexibility.In a nutshell those are my two biggest points for the contribution.
OK, well I have taken that on board and put together a script to run over the code base. I've opened a pull requests for each.
I agree that some documentation would be good for the templates!
I don't think we should drop the collecttemplates command though because some people don't use a "theme" and just want to put templates in their project's templates directory (that is what I often do).� Collecttemplates can also be used with the -t option to only copy over specific templates so it can be used, and I think should used, to only get the file[s] you are extending.
It also can be educational to copy all templates into a single hierarchy since if you browse the templates in the source they are scattered
among the various Mezzanine apps.� Even if you don't leave all the templates copied over it provides a nice overview of the templates that exist.
On another line of thought:
I was thinking that if we end up going with abstract template inheritance we could add an option to the collecttemplates command which would determine whether or not the abstract template was copied with the requested template (default would be to not copy it).
On Mon, May 7, 2012 at 3:22 AM, POKOLI I PUNTO <pok...@gmail.com> wrote:
IMHO the collecttemplates command should be dropped and the theme developer would need to include all the extended files in the theme (app) it is developing. This will save the theme to not include the files they are not extending.
This change would force to add a page in the docs describing which is the responsibility of each template. A good example is the wordpress one: http://codex.wordpress.org/Stepping_Into_Templates
Just my 2 cents!
Al 06/05/12 03:01, En/na Stephen McDonald ha escrit:
Debating the naming convention might seem like bikeshedding, but I think it's really important. If one approach clearly communicates the intention and another doesn't, then it's worthwhile discussing it.
So here's another idea: instead of page.html and _page.html, we use page.html and page.base.html - this way at least all the template lines up together in a large directory listing, and it clearly indicates the intention. I was first thinking page.html.base which would line up even close, but you'd lose syntax highlighting in your editor.
On Sun, May 6, 2012 at 10:51 AM, Stephen McDonald <st...@jupo.org> wrote:
Also discussed: the bearing this has on the collecttemplates command. If every view has two templates, do we copy both? One or the other? Do we drop the command from the project?
On Sun, May 6, 2012 at 10:47 AM, Stephen McDonald <st...@jupo.org> wrote:
I'll have a crack at it:
* page view looks for page.html - uses the version in the project's templates directory, otherwise app directory (probably in Mezzanine)* developer wants to customize page.html in their project, so they copy it to the project's template directory* they only want to modify one block in it, not copy the entire template, which may include a lot of functionality, that could change in future versions.* they can't have proj/templates/page.html extend the app version of page.html, Django doesn't know how to deal with extending the same template name/path* proposed solution: view still looks for page.html, but app's page.html has one line: {% extends "_page.html" %}, and all the functionality lives in _page.html in the app
* developer can then in their project's templates directory, either have page.html with�{% extends "_page.html" %} and overriding only the block they need, or _page.html and reimplement the page's functionality entirely, depending on their needs (this is what currently occurs btw)
Current discussion are around:
* is this separation confusing - something that will definitely vary dev to dev. There's no question around the benefit it provides, it's a very good thing.* naming convention - should it be something other than _name.html, perhaps in a different directory, perhaps requiring middleware* can we modify the "extends" template tag, to allow this to occur without splitting things out. eg: page.html in proj/templates can {% extend "page.html" %} and the app version will be extended.
If I've missed anything please correct me.
On Sun, May 6, 2012 at 10:35 AM, Lee Matos <madmed...@gmail.com> wrote:
On May 5, 2012, at 8:19 PM, Joe Julian wrote:
> I agree. Though I have no fear of, and they conceptually suggest an internal object, using underscores, I have to agree that a "template path" seems more Django-like to me. Taking that a step further, this also opens up the opportunity to publish other templates. They would also be added in middleware. My Pixel template would extend the mezzanine template, and your site template could further extend my Pixel one. It makes sense to me.
>
> Josh Cartmell <joshc...@gmail.com> wrote:
>
>> So it took me a few minutes to understad how this worked, but I agree with
>> Steve that once I got it it made sense. �The biggest problem I see with it
>> is that it will create an entry barrier for other Django developers as it
>> works differently than what you would traditionally see in a Django app.
>>
>> A thought I had to make extending easier without adding syntax that is not
>> always easy to understand is the following:
>>
>> Move all templates, in mezzanine, to a directory called mezzanine. �So
>> instead of index.html and pages/page.html etc... we would have
>> mezzanine/index.html and mezzanine/pages/page.html etc...
>>
>> If you were visiting the index page we would still ask Django for
>> index.html (not mezzanine/index.htlm). �Then in the mezzanine template
>> middleware we could add mezzanine/template_name.html to the path. �So first
>> Django would look for index.html, then mezzanine/index.html (this would be
>> similar to the way we can add specific device or host templates).
>>
>> If you wanted to extend index.html you would simply make a template called
>> index.html that looked like this:
>>
>> {% extends "mezzanine/index.html" %}
>> ...
>> your template
>> ...
>>
>> You could put anything you wanted in there because there would be no
>> circular import (extending mezzanine/index.html rather than index.html).
>> If you didn't create your own index.html it wouldn't matter because the
>> middleware would make it so that Django looked for index.html and
>> mezzanine/index.html
>>
>> You would also be free to create an index.html and not extend
>> mezzanine/index.html because index.html would come before
>> mezzanine/index.html in the template search.
>>
>> I got the idea for this based on the way django allows you to override
>> admin templates on a per app basis :
>> https://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-vs-replacing-an-admin-template
>>
>> What do you guys think? �I think this preserves all the power of Gary's
>> idea without making things more confusing.
>>
>> On Sat, May 5, 2012 at 6:47 AM, Gary Reynolds <
>> gary.r...@touchtechnology.com.au> wrote:
>>
>>> I'll try and answer inline to each comment rather than top posting ;)
>>>
>>> It's definitely me being thick, but it took a while to understand what
>>> you meant by "circular nature". It's that this template fragment is going
>>> to be put in a file also named "foo.html", right? It seems obvious after
>>> realizing it, but for some reason it took a while. :-)
>>>
>>> This is what I was referring to as the extra mental step. I had to think
>>> about the structure for a bit before it clicked, but once it did it makes
>>> sense. I guess what I was getting at is how many people will this happen
>>> for, and how big a step is it really. It'll vary across people I guess.
>>>
>>> Sure, I can appreciate that it is not immediately obvious, which is why�
>>> � - If you use {% extends %} in a template, it must be the first
>>> � template tag in that template. Template inheritance won't work, otherwise.
>>>
>>> I'm glad we've got some lively discussion on the topic anyway, looking
>>> forward to more.
>>>
>>> Gary
>>>
I'm not sure what you mean by circular importing? I thought I had a decent handle on django tempting and imports/extending/overriding and this doesn't seem to be solving anything for me. Is this being used anywhere else across the Django community? If it's not something that is widely used/ miles better than the current solution, I think it could be a stumbling block for new users as well. Can someone try and explain what circular dependency issue we are looking to solve? I'm genuinely curious but slightly confused as I'm being blinded by "the magic" at hand. :) I'm not trying to flame and I'm not saying this is necessarily a bad idea, I'm just not sure of the implications.
-Lee
What's the main objective of copying all the templates to the project specific dir? Change the only ones you need to customize? To avoid duplicating the files i think that the modified templates would be the only once that would need to be copied.
Another option is to deliver mezzanine with a default theme (with all the templates that exist now) and let the theme developer copy this files as base of the new theme if they want. This implies grouping all the templates in a separate dir. This is the way Wordpress works.
Al 07/05/12 20:25, En/na Josh Cartmell ha escrit:
I agree that some documentation would be good for the templates!
I don't think we should drop the collecttemplates command though because some people don't use a "theme" and just want to put templates in their project's templates directory (that is what I often do). Collecttemplates can also be used with the -t option to only copy over specific templates so it can be used, and I think should used, to only get the file[s] you are extending.
It also can be educational to copy all templates into a single hierarchy since if you browse the templates in the source they are scattered
among the various Mezzanine apps. Even if you don't leave all the templates copied over it provides a nice overview of the templates that exist.
On another line of thought:
I was thinking that if we end up going with abstract template inheritance we could add an option to the collecttemplates command which would determine whether or not the abstract template was copied with the requested template (default would be to not copy it).
On Mon, May 7, 2012 at 3:22 AM, POKOLI I PUNTO <pok...@gmail.com> wrote:
IMHO the collecttemplates command should be dropped and the theme developer would need to include all the extended files in the theme (app) it is developing. This will save the theme to not include the files they are not extending.
This change would force to add a page in the docs describing which is the responsibility of each template. A good example is the wordpress one: http://codex.wordpress.org/Stepping_Into_Templates
Just my 2 cents!
Al 06/05/12 03:01, En/na Stephen McDonald ha escrit:
Debating the naming convention might seem like bikeshedding, but I think it's really important. If one approach clearly communicates the intention and another doesn't, then it's worthwhile discussing it.
So here's another idea: instead of page.html and _page.html, we use page.html and page.base.html - this way at least all the template lines up together in a large directory listing, and it clearly indicates the intention. I was first thinking page.html.base which would line up even close, but you'd lose syntax highlighting in your editor.
On Sun, May 6, 2012 at 10:51 AM, Stephen McDonald <st...@jupo.org> wrote:
Also discussed: the bearing this has on the collecttemplates command. If every view has two templates, do we copy both? One or the other? Do we drop the command from the project?
On Sun, May 6, 2012 at 10:47 AM, Stephen McDonald <st...@jupo.org> wrote:
I'll have a crack at it:
* page view looks for page.html - uses the version in the project's templates directory, otherwise app directory (probably in Mezzanine)* developer wants to customize page.html in their project, so they copy it to the project's template directory* they only want to modify one block in it, not copy the entire template, which may include a lot of functionality, that could change in future versions.* they can't have proj/templates/page.html extend the app version of page.html, Django doesn't know how to deal with extending the same template name/path* proposed solution: view still looks for page.html, but app's page.html has one line: {% extends "_page.html" %}, and all the functionality lives in _page.html in the app
* developer can then in their project's templates directory, either have page.html with {% extends "_page.html" %} and overriding only the block they need, or _page.html and reimplement the page's functionality entirely, depending on their needs (this is what currently occurs btw)
Current discussion are around:
* is this separation confusing - something that will definitely vary dev to dev. There's no question around the benefit it provides, it's a very good thing.* naming convention - should it be something other than _name.html, perhaps in a different directory, perhaps requiring middleware* can we modify the "extends" template tag, to allow this to occur without splitting things out. eg: page.html in proj/templates can {% extend "page.html" %} and the app version will be extended.
If I've missed anything please correct me.
On Sun, May 6, 2012 at 10:35 AM, Lee Matos <madmed...@gmail.com> wrote:
On May 5, 2012, at 8:19 PM, Joe Julian wrote:
> I agree. Though I have no fear of, and they conceptually suggest an internal object, using underscores, I have to agree that a "template path" seems more Django-like to me. Taking that a step further, this also opens up the opportunity to publish other templates. They would also be added in middleware. My Pixel template would extend the mezzanine template, and your site template could further extend my Pixel one. It makes sense to me.
>
> Josh Cartmell <joshc...@gmail.com> wrote:
>
>> So it took me a few minutes to understad how this worked, but I agree with
>> Steve that once I got it it made sense. The biggest problem I see with it
>> is that it will create an entry barrier for other Django developers as it
>> works differently than what you would traditionally see in a Django app.
>>
>> A thought I had to make extending easier without adding syntax that is not
>> always easy to understand is the following:
>>
>> Move all templates, in mezzanine, to a directory called mezzanine. So
>> instead of index.html and pages/page.html etc... we would have
>> mezzanine/index.html and mezzanine/pages/page.html etc...
>>
>> If you were visiting the index page we would still ask Django for
>> index.html (not mezzanine/index.htlm). Then in the mezzanine template
>> middleware we could add mezzanine/template_name.html to the path. So first
>> Django would look for index.html, then mezzanine/index.html (this would be
>> similar to the way we can add specific device or host templates).
>>
>> If you wanted to extend index.html you would simply make a template called
>> index.html that looked like this:
>>
>> {% extends "mezzanine/index.html" %}
>> ...
>> your template
>> ...
>>
>> You could put anything you wanted in there because there would be no
>> circular import (extending mezzanine/index.html rather than index.html).
>> If you didn't create your own index.html it wouldn't matter because the
>> middleware would make it so that Django looked for index.html and
>> mezzanine/index.html
>>
>> You would also be free to create an index.html and not extend
>> mezzanine/index.html because index.html would come before
>> mezzanine/index.html in the template search.
>>
>> I got the idea for this based on the way django allows you to override
>> admin templates on a per app basis :
>> https://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-vs-replacing-an-admin-template
>>
>> What do you guys think? I think this preserves all the power of Gary's
>> idea without making things more confusing.
>>
>> On Sat, May 5, 2012 at 6:47 AM, Gary Reynolds <
>> gary.r...@touchtechnology.com.au> wrote:
>>
>>> I'll try and answer inline to each comment rather than top posting ;)
>>>
>>> It's definitely me being thick, but it took a while to understand what
>>> you meant by "circular nature". It's that this template fragment is going
>>> to be put in a file also named "foo.html", right? It seems obvious after
>>> realizing it, but for some reason it took a while. :-)
>>>
>>> This is what I was referring to as the extra mental step. I had to think
>>> about the structure for a bit before it clicked, but once it did it makes
>>> sense. I guess what I was getting at is how many people will this happen
>>> for, and how big a step is it really. It'll vary across people I guess.
>>>
>>> Sure, I can appreciate that it is not immediately obvious, which is why…
>>> - If you use {% extends %} in a template, it must be the first
>>> template tag in that template. Template inheritance won't work, otherwise.
>>>
>>> I'm glad we've got some lively discussion on the topic anyway, looking
>>> forward to more.
>>>
>>> Gary
>>>
I'm not sure what you mean by circular importing? I thought I had a decent handle on django tempting and imports/extending/overriding and this doesn't seem to be solving anything for me. Is this being used anywhere else across the Django community? If it's not something that is widely used/ miles better than the current solution, I think it could be a stumbling block for new users as well. Can someone try and explain what circular dependency issue we are looking to solve? I'm genuinely curious but slightly confused as I'm being blinded by "the magic" at hand. :) I'm not trying to flame and I'm not saying this is necessarily a bad idea, I'm just not sure of the implications.
-Lee
So if I understand that correctly it just looks down the template search path for another instance of the same named template?
I haven't had a chance to try it out yet but I'm wondering what you happen in the following situation:my INSTALLED_APPS looks like this (default project with custom_app at the end:INSTALLED_APPS = (...django stuff......mezzanine stuff..."custom_app")I have index.html in my projects templates directory and it extends index.html. custom_app also has an index.html which extends index.html. What would custom_app's index.html extend?
To try this out where would we need to put the code from the gist?
On Wed, May 9, 2012 at 2:26 AM, Josh Cartmell <joshc...@gmail.com> wrote:
So if I understand that correctly it just looks down the template search path for another instance of the same named template?Yes that's how it works - and it just removes the path of the current template that {% extends %} is being used in, and then the regular ordering of finding the template applies.I haven't had a chance to try it out yet but I'm wondering what you happen in the following situation:my INSTALLED_APPS looks like this (default project with custom_app at the end:INSTALLED_APPS = (...django stuff......mezzanine stuff..."custom_app")I have index.html in my projects templates directory and it extends index.html. custom_app also has an index.html which extends index.html. What would custom_app's index.html extend?I don't think it'd handle this situation (eg more than one level of inheritance) - would need to work on it more to get that happening.
This felt like a show-stopper, even though I think the newly dubbed "Abstract template inheritance" approach would suffer from the same shortcoming. However I've managed to get n levels of inheritance working and updated the gist: https://gist.github.com/2634461So this approach (dubbing it "overextend") has that going for it as well. This allows for the *extreme* case where someone is developing a reusable theme as an app with page.html, they "overextend" Mezzanine's page.html, and with the theme installed (top of INSTALLED_APPS), the project developer's page.html would overextend the theme app's page.html, which will still overextend Mezzanine's page.html - all the things like {{ block.super }} work as expected, and somehow it all managed to works with Django's cached template loader too.
I may be missing something, but template inheritance depends on being {% extends %} being the first template tag in the template. Adding {% overextends %} would require a {% load %}, which as I understand it, would leave this contract broken?
Assuming that isn't an issue, I then suppose that it needs to be considered whether {% overextends %} can therefore exist anywhere in template, or must immediately follow a {% load %} tag, etc.
Also {% overextends %} will be a mezzanine only concept; it would have no point of reference itself in any of the shipped templates because they won't collide by definition - they are the abstract bases using ATI nomenclature.
ATI could be an approach any developer writing a reusable application could adopt, with Mezzanine as a blueprint.Yes, it is a little more invasive, but I think that In the face of ambiguity, refuse the temptation to guess and by having the extra files we satisfy Explicit is better than implicit are both dealt with better by ATI than the overextends approach.On 9 May 2012 14:15, Josh Cartmell <joshc...@gmail.com> wrote:
I really like the idea of an {% overextends %} template tag and prefer it to creating a companion template for every template. It is less invasive and should be easier to maintain. Either method accomplishes the same purpose so I vote for the simpler one.It might be nice to be able to optionally specify an app with overextends. So {% overextends "index.html" "mezzanine.core" %} would inherit from mezzanine's index.html (this would help avoid accidentally inheriting from something you didn't intend to). If an app was not specified then the normal template inheritance hierarchy could be used as discussed.