Skip to content

Commit 97bb614

Browse files
authored
Merge pull request #1525 from plone/mrtango-improve-views-chapter
add plone.api.content.get_view method example
2 parents f4038a8 + 1c204d7 commit 97bb614

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

docs/classic-ui/views.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ The same functionality can be achieved with helper views, with less potential pi
751751
752752
(classic-ui-reusing-view-template-snippets-or-embedding-another-view-label)=
753753
754-
## Reusing view template snippets or embedding another view
754+
## Reusing view template snippets (macros) or embedding another view
755755
756756
To use the same template code several times you can either:
757757
@@ -820,9 +820,38 @@ You need to get access to the view in your code if you are:
820820
- calling a view from inside another view, or
821821
- calling a view from your unit test code.
822822
823-
Below are two different approaches for that.
823+
Below are three different approaches for that.
824824
825825
826+
(classic-ui-view-by-plone-api)=
827+
828+
### By using `plone.api.content.get_view()`
829+
830+
The `plone.api` provides a method to get a view by its registered name, the context, and the current request.
831+
832+
```python
833+
from plone import api
834+
835+
portal = api.portal.get()
836+
view = api.content.get_view(
837+
name='plone',
838+
context=portal['about'],
839+
request=request,
840+
)
841+
```
842+
843+
```{versionchanged} 2.0.0
844+
Since version 2.0.0, the request argument can be omitted.
845+
In that case, the global request will be used.
846+
847+
For more details see {ref}`content-get-view-example`.
848+
```
849+
850+
```{note}
851+
The usage of `plone.api` in Plone core is limited.
852+
If in doubt, please use the following methods instead.
853+
```
854+
826855
(classic-ui-by-using-getmultiadapter-label)=
827856
828857
### By using `getMultiAdapter()`

0 commit comments

Comments
 (0)