Creating widgets is really easy. After all, it is nothing more than writing a
page template to produce HTML which will be invoked by an Editor Field from an
ERP5 Form which acts as the layout for a Web Section.
However, our experience is that most widgets, even for the simplest purpose,
are not well written and lead to performance or stability issues in Web Sites.
We would like to give here a couple of advice to write better widgets.
Table of Contents
Here is an example of widget:
This widget displays <explain here what it does>
* <missing feature which must be implemented still>
* <an issue which still needs to be fixed>
<ul tal:define="current_web_section python:request.get('current_web_section', here)">
<li tal:repeat="subsection python:current_web_section.WebSection_getSiteMapTree(depth=1)"><a href="#" tal:content="subsection/translated_title"
tal:attributes="href subsection/url">Menu item</a></li>
Let us review the good practices which were followed:
Association a widget to one of the default caches of ERP5 Web (web_site_ram_cache,
web_section_ram_cache, etc.) can dramatically improve performance.
Currently, this only works for Page Template, Image, etc. But it will soon
work too for ERP5 Forms. The default caches provide the following behaviour:
Other caches (ex. http_cache) do not apply for widgets. If you want to cache content with HTTP cache, use gadgets.
If you need to display a tree of documents, a list of sections, a site map,
and if it is not enough, try to extend it to make it more universal, more convenient, etc.
if you need to display a list of documents, always consider the following:
By doing it this way, you create a strict separation between:
One could for example create a list of articles with title, date, summary, author, number of comments by creating:
The same renderer could be used by another ListBox field to render the latest
products in an online shop, the latest support tickets, etc. By splitting the
listing logic from the rendering logic, a given renderer can be reused in different
There are 2 kinds of URLs in an ERP5 web site:
Never use anything else. Never use in particular getUrl, getPhysicalPath, getRelativeUrl