Skip to content

Commit dcdec0b

Browse files
authored
Document the @@render-portlet view. (#2089)
* Document the @@render-portlet view. Documentation about the @@render-portlet view, which can be used to reload a portlet via AJAX.
1 parent ebe45df commit dcdec0b

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

docs/classic-ui/portlets.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ As a user, you can add a portlet to a web page in a Plone site by following thes
4040
If you do not see the {guilabel}`Manage portlets` link, you may need to contact the site administrator to request access.
4141

4242
3. In the {menuselection}`Add portlets` menu, select the portlet type that you want to add, and click the {guilabel}`Add` button.
43-
This will open a form to edit the settings for the selected portlet type.
43+
This will open a form to edit the settings for the selected portlet type.
4444

4545
4. Click the {guilabel}`Save` button to save your changes and add the portlet to the web page.
4646
This adds the portlet to the list of {guilabel}`Portlets assigned here` on the screen.
@@ -50,7 +50,6 @@ As a user, you can add a portlet to a web page in a Plone site by following thes
5050
The {guilabel}`X` button deletes the portlet.
5151
These options will only appear at the root from which the object inherits its settings.
5252

53-
5453
## Writing a custom Portlet
5554

5655
To create a portlet, you will need to write Python classes that define the portlet and its behavior.
@@ -202,3 +201,29 @@ These values should match the corresponding classes and interfaces defined in th
202201
This file registers the `MyPortlet` class as a portlet with Plone. It also specifies the portlet's name, title, description, and category.
203202

204203
For more examples of how to write and register portlets, look at the source code of the Plone core package [`plone.app.portlets`](https://github.com/plone/plone.app.portlets), or of other Plone add-ons that include portlets.
204+
205+
## Call one portlet by URL
206+
207+
To call a portlet by its URL, for example, to update it via an AJAX call, use the `@@render-portlet` view in your portlet renderer with `portlethash` as a query parameter.
208+
209+
The following example shows how to construct a reload URL for a portlet.
210+
211+
```python
212+
from plone.app.portlets.portlets.base import Renderer
213+
from Products.CMFPlone.utils import safe_unicode
214+
215+
216+
class BasePortletRenderer(Renderer):
217+
@property
218+
def hash(self):
219+
portlethash = self.request.form.get(
220+
"portlethash", getattr(self, "__portlet_metadata__", {}).get("hash", "")
221+
)
222+
return portlethash
223+
224+
@property
225+
def reload_url(self):
226+
base_url = self.context.absolute_url()
227+
hash = safe_unicode(self.hash)
228+
return f"{base_url}/@@render-portlet?portlethash={hash}"
229+
```

0 commit comments

Comments
 (0)