Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
PLIP: Reuse code among portlets, tiles and views #1755
Proposer : @rodfersou
Seconder : @hvelarde
Move small applets in different layout machinery existent in Plone
Some applets like portlet calendar are really complex, and there is no point to rewrite this code when need it in other places of Plone.
Define where the code should be centralized, and what is the better way to share code and template.
Proposal & Implementation
One place for code and templates, reused for portlets, tiles and views in a easy way.
Depend on how we are going to achieve this.
We started with an implementation using mixins and macros, but it was pointed that this is not the better way to go plone/plone.app.event#243
we wanted to do that during the Mephisto Sprint but obviously that was not a good idea as developers were focused on other things.
@datakurre sugested to move the resulting code to plone.app.layout; @thet and @jensens didn't like the idea of mixins and suggested adapters as an option but we have no experience on that and need some code examples.
So we need a snippet for that which is code+template, has access to the context and request...
So just a view, right?
Then the view can be rendered in different scenarios such as portlet, tile, viewlet and so on by just looking it up and calling it in the template maybe like so:
This could be looked up and called in code too.
Just an idea, open for better/simpler solutions.
I've done that like described by @jensens numerous times, except for passing parameters. But for parameters, you can also do:
just dummy code and also just an idea...
@gforcada, do you have measurements here? In restricted templates that may be true (i never profiled this with chameleon), but with chameleon and unrestricted templates (which we are talking about) from my experience tales expressions are slower than native python. This is true in pyramid as well btw, where python expressions are default.
@jensens what are restricted/unrestricted templates? AFAIK any template has to go through the template engine (zope.tal, chameleon) and they are patched to go trough RestrictedPython, right? That's what I read about it, and since then moved as much logic as possible to python code(views) rather than on the templates
Hi everyone, I need your help to decide where the code should be placed, then I can create the view and move the code.
It would be nice if we can decide it today, since we have a customer waiting for this change.
@datakurre could you please share your thoughts about it?
@gforcada From my understanding and from a look at
If you look at
This also explains why templates customized through the ZMI
So, in short