Skip to content

Commit b48309e

Browse files
committed
Add section heading labels.
One sentence per line.
1 parent 169906d commit b48309e

File tree

1 file changed

+106
-19
lines changed

1 file changed

+106
-19
lines changed

docs/classic-ui/views.md

Lines changed: 106 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,37 +32,46 @@ Views are usually a combination of:
3232
}
3333
```
3434

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.
3539

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).
4042

4143
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.
46+
47+
48+
(classic-ui-creating-and-registering-a-view-label)=
4549

4650
## Creating and registering a view
4751

48-
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)=
4956

5057
### Creating a view
5158

5259
Create your add-on package using {term}`plonecli`:
5360

5461
```shell
55-
56-
$ plonecli create addon collective.awesomeaddon
62+
plonecli create addon collective.awesomeaddon
5763
```
5864

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:
6066

6167
```shell
62-
63-
$ plonecli add view
68+
cd collective.awesomeaddon
69+
plonecli add view
6470
```
6571

72+
73+
(classic-ui-python-logic-code-label)=
74+
6675
#### Python logic code
6776

6877
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
109118
method which `__call__()` or view users can explicitly call.
110119
```
111120

121+
122+
(classic-ui-registering-a-view-label)=
123+
112124
#### Registering a view
113125

114126
```{todo}
@@ -182,6 +194,8 @@ You need to declare the `browser` namespace in your
182194
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>`.
183195

184196

197+
(classic-ui-page-template-label)=
198+
185199
#### Page template
186200

187201
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
211225

212226
When you restart Plone, and activate your add-on, the view should be available through your browser.
213227

228+
229+
(classic-ui-accessing-your-newly-created-view-label)=
230+
214231
#### Accessing your newly created view
215232

216233
Now you can access your view within the news folder:
@@ -235,6 +252,9 @@ to have the same id as a view:
235252
http://localhost:8080/Plone/news/@@my-view
236253
```
237254

255+
256+
(classic-ui-content-slots-label)=
257+
238258
### Content slots
239259

240260
```{todo}
@@ -267,6 +287,9 @@ inherits from `<html metal:use-macro="context/main_template/macros/master">`:
267287
content-core slot if you wish to use the stock content-title provided by the
268288
main template.
269289

290+
291+
(classic-ui-relationship-between-views-and-templates-label)=
292+
270293
### Relationship between views and templates
271294

272295
The ZCML `<browser:view template="">` directive will set the `index`
@@ -334,6 +357,8 @@ class MyView(BrowserView):
334357
```
335358

336359

360+
(classic-ui-several-templates-per-view-label)=
361+
337362
### Several templates per view
338363

339364
You can bind several templates to one view and render them individually.
@@ -365,6 +390,9 @@ And then in the template call:
365390
<div tal:replace="structure view/render_template2">
366391
```
367392

393+
394+
(classic-ui-view-init-method-special-cases-label)=
395+
368396
#### View `__init__()` method special cases
369397

370398
```{todo}
@@ -381,6 +409,9 @@ This information is set after the constructor have been run.
381409
All Plone code which relies on acquisition chain, which means almost all Plone helper code, does not work in `__init__()`.
382410
Thus, the called Plone API methods return `None` or tend to throw exceptions.
383411

412+
413+
(classic-ui-layers-label)=
414+
384415
### Layers
385416

386417
Views can be registered against a specific {ref}`layer <classic-ui-layers-label>` interface.
@@ -398,7 +429,9 @@ You should register your views against a certain layer in your own code.
398429
For more information, read the {ref}`classic-ui-layers-label` chapter.
399430

400431

401-
### Register and unregister view directly using zope.component architecture
432+
(classic-ui-register-and-unregister-view-directly-using-zope.component-architecture-label)=
433+
434+
### Register and unregister view directly using `zope.component` architecture
402435

403436
Example how to register:
404437

@@ -429,6 +462,9 @@ gsm.unregisterAdapter(factory=TestingRedirectHandler,
429462
name="redirect_handler")
430463
```
431464

465+
466+
(classic-ui-customizing-views-label)=
467+
432468
## Customizing views
433469

434470
To customize existing Plone core or add-on views you have different options.
@@ -438,6 +474,9 @@ To customize existing Plone core or add-on views you have different options.
438474
In this case, you override the Python class by using your own add-on which
439475
installs a view class replacement using an add-on specific `browser layer`.
440476

477+
478+
(classic-ui-overriding-view-template-label)=
479+
441480
### Overriding view template
442481

443482
The recommended approach to customize `.pt` files for Plone is to use a little helper called [z3c.jbot](https://pypi.python.org/pypi/z3c.jbot).
@@ -451,7 +490,10 @@ If you need to override templates in core Plone or in an existing add-on, you ca
451490
viewlets, old style page templates and portlets.
452491
In fact it can override any `.pt` file in the Plone source tree, except the main_template.pt.
453492

454-
### Overriding a template using z3c.jbot
493+
494+
(classic-ui-overriding-a-template-using-z3c.jbot-label)=
495+
496+
### Overriding a template using `z3c.jbot`
455497

456498
1. First of all, make sure that your customization add-on supports [z3c.jbot](https://pypi.python.org/pypi/z3c.jbot).
457499
Add-on packages created by plonecli have an `overrides` folder in the `browser` folder where you can
@@ -513,6 +555,8 @@ If you want to override an already overridden template, read here:
513555
http://stackoverflow.com/questions/16209392/how-can-i-override-an-already-overriden-template-by-jbot
514556

515557

558+
(classic-ui-overriding-a-view-class-label)=
559+
516560
## Overriding a view class
517561

518562
In this example we override the `@@register` form from the
@@ -580,10 +624,7 @@ You can also add a view to your package via {term}`plonecli` and place the Pytho
580624
```
581625

582626

583-
584-
585-
586-
627+
(classic-ui-guided-information-label)=
587628

588629
## Guided information
589630

@@ -594,6 +635,8 @@ The Mastering Plone Training has several chapters on views.
594635
- {ref}`training:views3-label`
595636

596637

638+
(classic-ui-anatomy-of-a-view-label)=
639+
597640
## Anatomy of a view
598641

599642
```{todo}
@@ -657,6 +700,9 @@ However, in the most of cases
657700
Views rendering page snippets and parts can be subclasses of zope.publisher.browser.BrowserView directly
658701
as snippets might not need acquisition support which adds some overhead to the rendering process.
659702

703+
704+
(classic-ui-helper-views-label)=
705+
660706
## Helper views
661707

662708
Not all views need to return HTML output, or output at all.
@@ -667,11 +713,17 @@ add-on product can customize or override in a conflict-free manner.
667713
View methods are exposed to page templates and such, so you can also call
668714
view methods directly from a page template, not only from Python code.
669715

716+
717+
(classic-ui-more-information-label)=
718+
670719
### More information
671720

672721
- {doc}`Context helpers </develop/plone/misc/context>`
673722
- {doc}`Expressions </develop/plone/functionality/expressions>`
674723

724+
725+
(classic-ui-historical-perspective-label)=
726+
675727
### Historical perspective
676728

677729
Often, the point of using helper views is that you can have reusable
@@ -689,6 +741,9 @@ The same functionality can be achieved with helper views, with less
689741
potential pitfalls.
690742
```
691743

744+
745+
(classic-ui-reusing-view-template-snippets-or-embedding-another-view-label)=
746+
692747
## Reusing view template snippets or embedding another view
693748

694749
To use the same template code several times you can either:
@@ -765,6 +820,9 @@ template will not be translated.
765820
</div>
766821
```
767822

823+
824+
(classic-ui-accessing-a-view-instance-in-code-label)=
825+
768826
## Accessing a view instance in code
769827

770828
You need to get access to the view in your code if you are:
@@ -774,6 +832,9 @@ You need to get access to the view in your code if you are:
774832

775833
Below are two different approaches for that.
776834

835+
836+
(classic-ui-by-using-getmultiadapter-label)=
837+
777838
### By using `getMultiAdapter()`
778839

779840
This is the most efficient way in Python.
@@ -794,6 +855,9 @@ def getView(context, request, name):
794855
return view
795856
```
796857

858+
859+
(classic-ui-by-using-traversal-label)=
860+
797861
### By using traversal
798862

799863
Traversal is slower than directly calling `getMultiAdapter()`. However,
@@ -829,6 +893,9 @@ by using the `@@`-notation in traversing.
829893
</div>
830894
```
831895

896+
897+
(classic-ui-use-a-skin-based-template-in-a-five-view-label)=
898+
832899
### Use a skin-based template in a Five view
833900

834901
Use `aq_acquire(object, template_name)`.
@@ -856,8 +923,14 @@ class TelescopeView(BrowserView):
856923
target_obj.getDefaultLayout())()
857924
```
858925

926+
927+
(classic-ui-advanced-label)=
928+
859929
## Advanced
860930

931+
932+
(classic-ui-listing-available-views-label)=
933+
861934
### Listing available views
862935

863936
This is useful for debugging purposes:
@@ -870,6 +943,9 @@ from zope.publisher.interfaces.browser import IBrowserRequest
870943
views = registration.getViews(IBrowserRequest)
871944
```
872945

946+
947+
(classic-ui-listing-all-views-of-certain-type-label)=
948+
873949
#### Listing all views of certain type
874950

875951
How to filter out views which provide a certain interface:
@@ -885,6 +961,9 @@ views = registration.getViews(IBrowserRequest)
885961
views = [ view.factory for view in views if IBlocksView.implementedBy(view.factory) ]
886962
```
887963

964+
965+
(classic-ui-default-view-of-a-content-item-label)=
966+
888967
### Default view of a content item
889968

890969
```{todo}
@@ -916,6 +995,9 @@ More info:
916995
- {doc}`Context helpers and utilities </develop/plone/misc/context>`
917996
- <http://plone.293351.n2.nabble.com/URL-to-content-view-tp6028204p6028204.html>
918997

998+
999+
(classic-ui-allowing-the-contentmenu-on-non-default-views-label)=
1000+
9191001
### Allowing the contentmenu on non-default views
9201002

9211003
In general, the contentmenu (where the actions, display views, factory types,
@@ -933,6 +1015,9 @@ by configuring it via ZCML like so:
9331015
</class>
9341016
```
9351017

1018+
1019+
(classic-ui-zope-viewpagetemplatefile-vs-five-viewpagetemplatefile-label)=
1020+
9361021
## Zope ViewPageTemplateFile vs. Five ViewPageTemplateFile
9371022

9381023
```{warning}
@@ -966,6 +1051,8 @@ The difference is that the *Five* version supports:
9661051
version of `ViewPageTemplateFile` instances.
9671052

9681053

1054+
(classic-ui-views-and-automatic-member-variable-acquisition-wrapping-label)=
1055+
9691056
### Views and automatic member variable acquisition wrapping
9701057

9711058
View class instances will automatically assign themselves as a parent for all member

0 commit comments

Comments
 (0)