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
`Views` are the basic elements of modern Python web frameworks.
15
-
A view runs code to setup Python variables for a rendering template.
14
+
Views are the basic elements of modern Python web frameworks.
15
+
A {term}`view` runs code to set up Python variables for a rendering template.
16
16
The output is not limited to HTML pages and snippets, but may contain {term}`JSON`, file download payloads, or other data formats.
17
17
18
18
Views are usually a combination of:
@@ -32,13 +32,13 @@ Views are usually a combination of:
32
32
}
33
33
```
34
34
35
-
Templates should kept simple.
35
+
Templates should be kept simple.
36
36
Logic should be kept in a separate Python file.
37
37
This enhances readability and makes components more reusable.
38
38
You can override the Python logic, the template file, or both.
39
39
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
+
When you work 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).
42
42
43
43
Each `BrowserView` class is a Python callable.
44
44
The `BrowserView.__call__()` method acts as an entry point to executing the view code.
@@ -155,7 +155,7 @@ See below for comments about what the code does.
155
155
156
156
`name`
157
157
: The name by which the view is exposed to traversal and `getMultiAdapter()` look-ups.
158
-
If your view's name is `myview`, then you can render it in the browser by calling http://yourhost/site/page/@@myview.
158
+
If your view's name is `myview`, then you can render it in the browser by calling `http://yourhost/site/page/@@myview`.
159
159
160
160
`permission`
161
161
: This is the permission needed to access the view.
@@ -173,12 +173,7 @@ You need to declare the `browser` namespace in your `configure.zcml` to use `bro
173
173
```
174
174
175
175
The view in question is registered against a {ref}`layer <classic-ui-layers-label>`.
176
-
It will be available after restart, after running the {ref}`GenericSetup profile <backend-config-registry-generic-setup-label>`.
177
-
178
-
179
-
```{todo}
180
-
Fix the preceding link to "Add/remove in Site setup".
181
-
```
176
+
It will be available after restart, after running the {ref}`GenericSetup profile <backend-configuration-registry-generic-setup-label>`.
In the generated template above, we have a fill-slot attribute, which will fill the slot with the name `content-core`, which is defined in Plone's [main_template](https://github.com/plone/Products.CMFPlone/blob/master/Products/CMFPlone/browser/templates/main_template.pt).
238
+
In the generated template above, we have a `fill-slot` attribute, which will fill the slot with the name `content-core`, which is defined in Plone's [main_template](https://github.com/plone/Products.CMFPlone/blob/master/Products/CMFPlone/browser/templates/main_template.pt).
244
239
The following list shows the available options for `<metal fill-slot="">` in your template.
245
240
246
241
```{note}
247
242
Please note that our template above inherits from `<html metal:use-macro="context/main_template/macros/master">`.
248
243
```
249
244
250
-
#### Metadata in HEAD
245
+
#### Metadata in `head`
251
246
252
-
-`top_slot`
253
-
: Used to set parameters on the request, for example to deactivate the left and right columns or caching.
: Used to define HTML `head` elements, such as `link` tags for RSS and CSS.
260
+
261
+
`style_slot`
262
+
: Used to define `style` tags to load CSS files.
263
+
264
+
`javascript_head_slot`
265
+
: Used to define `script` tags to load JavaScript in the HTML `head` tag.
267
266
268
267
```{note}
269
-
Keep in mind that even though you can include CSS and JavaScript this way, most of the time you want to register it in the {rev}`Resource Registry <classic-ui-static-resources-label>`.
268
+
Keep in mind that even though you can include CSS and JavaScript this way, most of the time you should register it in the {ref}`resource registry <classic-ui-static-resources-label>`.
270
269
```
271
270
272
271
#### Global status message
273
272
274
-
-`global_statusmessage`
275
-
: Used to fill in global status messages.
273
+
`global_statusmessage`
274
+
: Used to fill in global status messages.
276
275
277
276
#### Content slots
278
277
279
-
-`content`
280
-
: The content area, including the title, description, content-core and viewlets around them.
278
+
`content`
279
+
: The content area, including the title, description, content-core and viewlets around them.
281
280
282
-
-`body`
283
-
: A slot inside the content macro.
281
+
`body`
282
+
: A slot inside the content macro.
284
283
285
-
-`main`
286
-
: Overrides the `main` slot in the main template.
287
-
You must render `title` and `description` yourself.
284
+
`main`
285
+
: Overrides the `main` slot in the main template.
286
+
You must render `title` and `description` yourself.
288
287
289
-
- `content-title`
290
-
: `title` and `description` prerendered for Plone version 4.x or greater.
288
+
`content-title`
289
+
: `title` and `description` prerendered for Plone version 4.x or greater.
291
290
292
-
- `content-description`
291
+
`content-description`
292
+
: Content description for your view.
293
293
294
-
- `content-core`
295
-
: content body specific to your view for Plone version 4.x or greater.
294
+
`content-core`
295
+
: Content body specific to your view for Plone version 4.x or greater.
@@ -413,7 +413,7 @@ And then in the template call:
413
413
The Python constructor method of the view, `__init__()`, is special.
414
414
You should almost never try to put your code there. Instead, use the `_call__()` method or further helper methods called from it.
415
415
416
-
The `__init__()` method of the view might not have an {ref}`acquisition chain <backend-traversing-label>` available, meaning that it does not know the parent or hierarchy where the view is.
416
+
The `__init__()` method of the view might not have an {ref}`acquisition chain <backend-traversing-label>` available, meaning that it does not know where is its parent or hierarchy.
417
417
This also means that you don't have user information and permissions for the view.
418
418
419
419
This information is set after the constructor has been run.
To customize existing Plone core or add-on views you have different options.
480
+
To customize existing Plone core or add-on views, you have different options.
481
481
482
-
- Usually you can simply override the related page template file (`.pt`).
482
+
- Usually you can override the related page template file (`.pt`).
483
483
- Sometimes you also need to change the related Python view class code.
484
484
In this case, you override the Python class by using your own add-on which installs a view class replacement using an add-on specific {term}`browser layer`.
485
485
@@ -488,7 +488,7 @@ To customize existing Plone core or add-on views you have different options.
488
488
489
489
### Overriding view template
490
490
491
-
The recommended approach to customize `.pt` files for Plone is to use a little helper called [z3c.jbot](https://pypi.python.org/project/z3c.jbot).
491
+
The recommended approach to customize `.pt` files for Plone is to use a little helper called [`z3c.jbot`](https://pypi.org/project/z3c.jbot/).
492
492
493
493
If you need to override templates in core Plone or in an existing add-on, you can do the following:
494
494
@@ -508,7 +508,7 @@ If you need to override templates in core Plone or in an existing add-on, you ca
508
508
509
509
2. Locate the template you need to override in the Plone source tree.
510
510
You can do this by searching in all the installed packages for `.pt` files.
511
-
If you are using buildout with the `collective.recipe.omelette` recipe, a good folder to search in is `./parts/omelette`.
511
+
If you use buildout with the `collective.recipe.omelette` recipe, a good folder to search in is `./parts/omelette`.
512
512
513
513
The following is an example UNIX `find` command to find `.pt` files.
514
514
You can also use Windows Explorer file search or similar tools:
@@ -561,7 +561,7 @@ If you need to override templates in core Plone or in an existing add-on, you ca
561
561
After the file is in place, changes to the file are instantly picked up.
562
562
The template code is re-read on every HTTP request.
563
563
564
-
If you want to override an already overridden template, read [How can I override an already overriden template by jbot?](https://stackoverflow.com/questions/16209392/2214933)
564
+
If you want to override an already overridden template, read [How can I override an already overriden template by jbot?](https://stackoverflow.com/questions/16209392/how-can-i-override-an-already-overriden-template-by-jbot).
565
565
566
566
567
567
(classic-ui-overriding-a-view-class-label)=
@@ -884,7 +884,7 @@ You can also do direct view look-ups and method calls in your template by using
### Allowing the `contentmenu` on non-default views
988
+
### Allow the `contentmenu` on non-default views
989
989
990
-
In general, the {guilabel}`contentmenu` (where the actions, display views, factory types,
991
-
workflow, and other select menus are located) is not shown on non-default views.
990
+
In general, the {guilabel}`contentmenu` (where the actions, display views, factory types, workflow, and other select menus are located) is not shown on non-default views.
992
991
There are some exceptions, though.
993
992
994
-
If you want to display the {guilabel}`contentmenu` in such non-default views, you have to
995
-
mark them with the `IViewView` interface from `plone.app.layout`, either by letting
996
-
the class provide `IViewView` by declaring it with `zope.component.implements` or
997
-
by configuring it via ZCML as follows:
993
+
If you want to display the {guilabel}`contentmenu` in such non-default views, you have to mark them with the `IViewView` interface from `plone.app.layout`, either by letting the class provide `IViewView` by declaring it with `zope.component.implements` or by configuring it via ZCML as follows:
998
994
999
995
```xml
1000
996
<class class="dotted.path.to.browser.view.class">
@@ -1005,15 +1001,14 @@ by configuring it via ZCML as follows:
- [`Five` version](https://github.com/zopefoundation/Zope/blob/d1814d0a6bddb615629b552de10e9aa5ad30a6da/src/Products/Five/browser/__init__.py#L20) with .
1016
-
[`Products.Five`](https://github.com/zopefoundation/Zope/blob/master/src/Products/Five/doc/manual.txt) is a way to access some Zope 3 technologies from the Zope codebase, which is used by Plone.
1011
+
- [`Five` version](https://github.com/zopefoundation/Zope/blob/d1814d0a6bddb615629b552de10e9aa5ad30a6da/src/Products/Five/browser/__init__.py#L20) with [`Products.Five`](https://github.com/zopefoundation/Zope/blob/master/src/Products/Five/doc/manual.txt) is a way to access some Zope 3 technologies from the Zope codebase, which is used by Plone.
1017
1012
1018
1013
Compare the differences in code.
1019
1014
@@ -1033,15 +1028,14 @@ The difference is that the `Five` version supports:
1033
1028
- The `provider:` TAL expression.
1034
1029
- Other Plone-specific TAL expression functions, such as `test()`.
1035
1030
- Usually, Plone code needs the `Five` version of `ViewPageTemplateFile`.
1036
-
- Some subsystems, notably the `z3c.form` package, expect the Zope 3 (not Five) version of `ViewPageTemplateFile` instances.
1031
+
- Some subsystems, notably the `z3c.form` package, expect the Zope 3 (not `Five`) version of `ViewPageTemplateFile` instances.
One workaround to avoid this mess is to use `aq_inner` when accessing `self.obj` values, as described in [Dealing with view implicit acquisition problems in Plone](https://stackoverflow.com/questions/11755348/2214933).
1074
-
1067
+
One workaround to avoid this mess is to use `aq_inner` when accessing `self.obj` values, as described in [Dealing with view implicit acquisition problems in Plone](https://stackoverflow.com/questions/11753940/dealing-with-view-implicit-acquisition-problems-in-plone/11755348#11755348).
0 commit comments