Hi. I want to compose a page, using a main template. A simple solution is to use macros class Resource(rend.rend): def macro_main(self, ctx): return loaders.xmlfile(...) The macro_main method is called only once. However it seems that macros are going to be removed, moreover if I change the child template, I have to reload the server. A solution is to use a render (code not tested): class Resource(rend.rend): template = ... # The child template to load def macro_main(self, ctx): return self.state.setdefault( template, loaders.xmlfile(self.template) ) Here I'm storing the loader instance in a dictionary, to optimize template loading. Is this solution as efficient as the one with macros? Thanks Manlio Perillo
On Wed, 21 Feb 2007 12:32:08 +0100, Manlio Perillo
Hi.
I want to compose a page, using a main template. A simple solution is to use macros
class Resource(rend.rend): def macro_main(self, ctx): return loaders.xmlfile(...)
The macro_main method is called only once.
However it seems that macros are going to be removed, moreover if I change
Not to my knowledge, at least I'd be opposed/incline to re-implement them because I use them extensively in all my projects.
the child template, I have to reload the server.
Not really... just change the macro too with something like touch.
A solution is to use a render (code not tested):
class Resource(rend.rend): template = ... # The child template to load
def macro_main(self, ctx): return self.state.setdefault( template, loaders.xmlfile(self.template) )
Here I'm storing the loader instance in a dictionary, to optimize template loading.
Useless, loaders already have a cache.
Is this solution as efficient as the one with macros?
macros are not a way to cache stuff, but to compose stuff dynamically at pre-compile time.
Valentino Volonghi aka Dialtone ha scritto:
On Wed, 21 Feb 2007 12:32:08 +0100, Manlio Perillo
wrote: Hi.
I want to compose a page, using a main template. A simple solution is to use macros
class Resource(rend.rend): def macro_main(self, ctx): return loaders.xmlfile(...)
The macro_main method is called only once.
However it seems that macros are going to be removed, moreover if I change
Not to my knowledge, at least I'd be opposed/incline to re-implement them because I use them extensively in all my projects.
Yes, they are very handy.
the child template, I have to reload the server.
Not really... just change the macro too with something like touch.
Thanks, I just forget it.
[...]
Regards Manlio Perillo
Valentino Volonghi aka Dialtone ha scritto:
On Wed, 21 Feb 2007 12:32:08 +0100, Manlio Perillo
wrote: [...] class Resource(rend.rend): template = ... # The child template to load
def render_main(self, ctx, data): return self.state.setdefault( template, loaders.xmlfile(self.template) )
Here I'm storing the loader instance in a dictionary, to optimize template loading.
Useless, loaders already have a cache.
I have read the loaders.py, and, as far as I can see, the cache is *inside* the loader instance. This means that the cache is destroyed when the loader istance goes out of the scope; the document is reloaded every time render_main is called. Regards Manlio Perillo
On Wed, 21 Feb 2007 13:03:30 +0100, Manlio Perillo
[...]
class Resource(rend.rend): template = ... # The child template to load
def render_main(self, ctx, data): return self.state.setdefault( template, loaders.xmlfile(self.template) )
Here I'm storing the loader instance in a dictionary, to optimize template loading.
Useless, loaders already have a cache.
I have read the loaders.py, and, as far as I can see, the cache is *inside* the loader instance.
This means that the cache is destroyed when the loader istance goes out of the scope; the document is reloaded every time render_main is called.
I see you are actually saving the loader in self.state and this wouldn't let the loader die. Anyway you just need to provide another class variable for the loader, seems easy.
participants (2)
-
Manlio Perillo
-
Valentino Volonghi aka Dialtone