Skip to content

Commit d0b6950

Browse files
committed
add plone.api.content.get_view method example
1 parent 0bf293d commit d0b6950

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

docs/classic-ui/views.md

Lines changed: 26 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,33 @@ 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 tree different approaches for that.
824824
825825
826+
(classic-ui-view-by-plone-api)
827+
### By using plone.api.content.get_view()
828+
829+
The plone.api provides a method to get a view by it's registered name, the context and the current request.
830+
831+
```python
832+
from plone import api
833+
834+
portal = api.portal.get()
835+
view = api.content.get_view(
836+
name='plone',
837+
context=portal['about'],
838+
request=request,
839+
)
840+
```
841+
842+
Since version 2.0.0, the request argument can be omitted. In that case, the global request will be used.
843+
844+
For more details see {ref}`content-get-view-example`.
845+
846+
```{note}
847+
The usage of plone.api in Plone core is limited, if in doubted please use the following methods instead.
848+
```
849+
826850
(classic-ui-by-using-getmultiadapter-label)=
827851
828852
### By using `getMultiAdapter()`

0 commit comments

Comments
 (0)