You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -32,37 +32,46 @@ Views are usually a combination of:
32
32
}
33
33
```
34
34
35
+
Templates should kept simple.
36
+
Logic should be kept in a separate Python file.
37
+
This enhances readability and makes components more reusable.
38
+
You can override the Python logic, the template file, or both.
35
39
36
-
Templates should kept simple and logic kept in a separate Python file. This enhances readability and makes components more reusable. You can override the Python logic or the template file, or both.
37
-
38
-
When you are working with Plone, the most common view type is `BrowserView`
39
-
from the [Products.Five](https://github.com/zopefoundation/Zope/blob/master/src/Products/Five/doc/manual.txt) package. Other view types are `DefaultView` from [plone.dexterity](https://github.com/plone/plone.dexterity/blob/master/plone/dexterity/browser/view.py) and `CollectionView` from [plone.app.contenttypes](https://github.com/plone/plone.app.contenttypes/blob/master/plone/app/contenttypes/browser/collection.py) package.
40
+
When you are working with Plone, the most common view type is `BrowserView` from the package [Products.Five](https://github.com/zopefoundation/Zope/blob/master/src/Products/Five/doc/manual.txt).
41
+
Other view types include `DefaultView` from [plone.dexterity](https://github.com/plone/plone.dexterity/blob/master/plone/dexterity/browser/view.py) and `CollectionView` from [plone.app.contenttypes](https://github.com/plone/plone.app.contenttypes/blob/master/plone/app/contenttypes/browser/collection.py).
40
42
41
43
Each `BrowserView` class is a Python callable.
42
-
The `BrowserView.__call__()` method acts as an entry point to executing
43
-
the view code. From Zope's point of view, even a function would be
44
-
sufficient, as it is a callable.
44
+
The `BrowserView.__call__()` method acts as an entry point to executing the view code.
45
+
From Zope's point of view, even a function would be sufficient, as it is a callable.
This shows how to create and register view in Plone.
52
+
This section shows how to create and register a view in Plone.
53
+
54
+
55
+
(classic-ui-creating-a-view-label)=
49
56
50
57
### Creating a view
51
58
52
59
Create your add-on package using {term}`plonecli`:
53
60
54
61
```shell
55
-
56
-
$ plonecli create addon collective.awesomeaddon
62
+
plonecli create addon collective.awesomeaddon
57
63
```
58
64
59
-
then change the directory into the created package and add a view:
65
+
Then change the directory into the created package, and add a view:
60
66
61
67
```shell
62
-
63
-
$ plonecli add view
68
+
cd collective.awesomeaddon
69
+
plonecli add view
64
70
```
65
71
72
+
73
+
(classic-ui-python-logic-code-label)=
74
+
66
75
#### Python logic code
67
76
68
77
Depending how you answered the questions, `plonecli` will generate a Python file like this for you `src/collective/awesomeaddon/views/my_view.py`:
@@ -109,6 +118,9 @@ Instead, use a pattern where you have a `setup()` or similar
109
118
method which `__call__()` or view users can explicitly call.
110
119
```
111
120
121
+
122
+
(classic-ui-registering-a-view-label)=
123
+
112
124
#### Registering a view
113
125
114
126
```{todo}
@@ -182,6 +194,8 @@ You need to declare the `browser` namespace in your
182
194
The view in question is registered against a {ref}`classic-ui-layers-label`, it will be available after restart, after you run {doc}`Add/remove in Site setup </develop/addons/components/genericsetup>`.
183
195
184
196
197
+
(classic-ui-page-template-label)=
198
+
185
199
#### Page template
186
200
187
201
Depending on how you answered the questions, `plonecli` was creating a {ref}`template <plone:classic-ui-templates-label>` for you.
@@ -211,6 +225,9 @@ Depending on how you answered the questions, `plonecli` was creating a {ref}`tem
211
225
212
226
When you restart Plone, and activate your add-on, the view should be available through your browser.
0 commit comments