Discussion:
rebase versus include
David Johnston
2011-11-03 17:05:01 UTC
Permalink
I am just trying to get the bigger picture when it comes to chaining
templates together. There is include and rebase to do this. It seems
to me that these do very similar things. Are both really needed?

With rebase, it appears that you can wrap your current template in
another template and you could do this indefinitely, building up a
larger and larger chain like those Russian nesting dolls.

With include, you start with the parent template and "include" a child
template. That child template could have it's own includes etc. So it
seems you are more or less doing the same thing but starting at the
other end; the outside working in.

So, is there really a need for both of these?

Also, I wonder what happens if (perhaps by mistake) you include a
template that itself has a rebase in it.
Dave
Iuri
2011-11-03 17:22:22 UTC
Permalink
Yes, include and rebase cover different use cases.

I can have two different base templates, and each page inherit from one of
them. In this case, I use *rebase*.

These two different base templates want to share some common parts, so I
can create small templates and *include* them in both templates.

A good comparison to include x rebase is composition x inheritance in OOP.
Both are able to solve your problem, but you should decide which is the
best to you.

cheers,
iuri
Post by David Johnston
I am just trying to get the bigger picture when it comes to chaining
templates together. There is include and rebase to do this. It seems
to me that these do very similar things. Are both really needed?
With rebase, it appears that you can wrap your current template in
another template and you could do this indefinitely, building up a
larger and larger chain like those Russian nesting dolls.
With include, you start with the parent template and "include" a child
template. That child template could have it's own includes etc. So it
seems you are more or less doing the same thing but starting at the
other end; the outside working in.
So, is there really a need for both of these?
Also, I wonder what happens if (perhaps by mistake) you include a
template that itself has a rebase in it.
Dave
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.
pgoetz
2011-11-03 18:06:55 UTC
Permalink
Post by David Johnston
So, is there really a need for both of these?
I learned about rebase first from reading the Django documentation and
was somewhat confused why anyone would want to take this backward
approach. Reading the bottle documentation cleared things up nicely.
Here is a simple way to think about these.

Use rebase when you already have some elaborate template {header,
footer, sidebar, etc.} into which you want insert some dynamic content
formatted using your template:

[*] = your piddly little template
[#%#%#%#%] = the mega-template of complexity

rebase: [*] ---> [#%#% [*] #%#%]

Use include when taking a modular approach; i.e. assembling a template
from smaller parts:

include: [header] + [left column] + [*] + [footer]
Post by David Johnston
Also, I wonder what happens if (perhaps by mistake) you include a
template that itself has a rebase in it.
Not sure, but my guess is that the rebase (containig the included
content) would be included in your template. Maybe try testing this
and report back?
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.
David Johnston
2011-11-03 19:28:51 UTC
Permalink
To answer one of my questions. I have one template called main which
"includes" another called table. If I then edit table and put in %rebase
plain (another template of mine), it wraps table in plain and then wraps
this in main. I guess it makes sense to do that and might be useful for
some things.
Post by pgoetz
Post by David Johnston
So, is there really a need for both of these?
I learned about rebase first from reading the Django documentation and
was somewhat confused why anyone would want to take this backward
approach. Reading the bottle documentation cleared things up nicely.
Here is a simple way to think about these.
Use rebase when you already have some elaborate template {header,
footer, sidebar, etc.} into which you want insert some dynamic content
[*] = your piddly little template
[#%#%#%#%] = the mega-template of complexity
rebase: [*] ---> [#%#% [*] #%#%]
Use include when taking a modular approach; i.e. assembling a template
include: [header] + [left column] + [*] + [footer]
Post by David Johnston
Also, I wonder what happens if (perhaps by mistake) you include a
template that itself has a rebase in it.
Not sure, but my guess is that the rebase (containig the included
content) would be included in your template. Maybe try testing this
and report back?
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.
Yuntao Li
2014-06-04 18:07:08 UTC
Permalink
Post by pgoetz
I learned about rebase first from reading the Django documentation and
was somewhat confused why anyone would want to take this backward
approach. Reading the bottle documentation cleared things up nicely.
Here is a simple way to think about these.
Use rebase when you already have some elaborate template {header,
footer, sidebar, etc.} into which you want insert some dynamic content
[*] = your piddly little template
[#%#%#%#%] = the mega-template of complexity
rebase: [*] ---> [#%#% [*] #%#%]
I don't understand what you mean above. Say I have an index.py to return
template('base'). Later, I want to insert some little templates in it. So I
make a template called mylittle_template.tpl. Now I need to modify 2
places:
1. add % rebase('base.tpl') to mylittle_template.tpl
2. modify index.py to return template('mylittle_template') instead of
return template('base')

Do I understand it right? If so, it means 2 places need to be modified.
However if I use include, I only need to add one line in base.tpl at the
place I wish % include('mylittle_template.tpl')
Post by pgoetz
Use include when taking a modular approach; i.e. assembling a template
include: [header] + [left column] + [*] + [footer]
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...