11---
22myst :
33 html_meta :
4- " description " : " "
5- " property=og:description " : " "
6- " property=og:title " : " "
7- " keywords " : " "
4+ " description " : " Configure custom views "
5+ " property=og:description " : " Configure custom views "
6+ " property=og:title " : " Configure custom views "
7+ " keywords " : " Plone, configure, custom views "
88---
99
1010# Custom views
1111
12- ** Configuring custom views and using display forms**
12+ This chapter describes how to configure custom views and use display forms.
1313
14- ## Simple views
1514
16- ** Creating basic views**
15+ ## Simple views
1716
18- So far, our types have used the default views.
19- They use the * display* widgets from [ z3c.form] , much like the add and edit forms use the * edit* widgets.
17+ So far our types have used the default views.
18+ They use the display widgets from [ ` z3c.form ` ] ( https://pypi.org/project/z3c.form/ ) , much like the add and edit forms use the edit widgets.
2019This is functional, but not very attractive.
2120Most types will need one or more custom view templates.
2221
2322Dexterity types are no different from any other content type in Plone.
2423You can register a view for your schema interface, and it will be available on your type.
25- If the view is named * view* , it will be the default view, at least if you use the standard FTI configuration.
26- This is because the FTI’ s ` default_view ` property is set to ` view ` , and ` view ` is in the list of ` view_methods. `
24+ If the view is named ` view ` , it will be the default view, at least if you use the standard {term} ` FTI ` configuration.
25+ This is because the FTI' s ` default_view ` property is set to ` view ` , and ` view ` is in the list of ` view_methods ` .
2726
28- First create a view registration with a ` <browser:page /> ` ZCML directive in your `` ` configure.zcml `` file:
27+ First create a view registration with a ` <browser:page /> ` ZCML directive in your {file} ` configure.zcml ` file.
2928
3029``` xml
3130<configure
3231 xmlns =" http://namespaces.zope.org/zope"
3332 xmlns : browser =" http://namespaces.zope.org/browser" >
3433
35- ...
36-
3734 <browser : page
3835 name =" view"
3936 for =" example.conference.program.IProgram"
@@ -45,7 +42,7 @@ First create a view registration with a `<browser:page />` ZCML directive in you
4542</configure >
4643```
4744
48- Secondly add a browser view in ` program.py ` as follows:
45+ Next add a browser view in ` program.py ` as follows.
4946
5047``` python
5148from Acquisition import aq_inner
@@ -74,7 +71,7 @@ You can add any methods to the view.
7471They will be available to the template via the ` view ` variable.
7572The content object is available via ` context ` .
7673
77- Finaly add a template in ` templates/programview.pt ` :
74+ Finaly add a template in {file} ` templates/programview.pt ` .
7875
7976``` html
8077<html xmlns =" http://www.w3.org/1999/xhtml" xml:lang =" en"
@@ -135,22 +132,20 @@ Finaly add a template in `templates/programview.pt`:
135132
136133For the most part, this template outputs the values of the various fields, using the ` sessions() ` method on the view to obtain the sessions contained within the program.
137134
138- ::: {note}
139- Notice how the ` details ` * RichText* field is output as ` tal:content="structure context/details/output" ` .
135+ ``` {note}
136+ Notice how the `details` ` RichText` field is output as `tal:content="structure context/details/output"`.
140137The `structure` keyword ensures that the rendered HTML is not escaped.
141- The extra traversal to ` details/output ` is necessary because the * RichText* field actually stores a * RichTextValue* object that contains not only the raw text as entered by the user, but also a MIME type (e.g. ` text/html ` ) and the rendered output text.
142- * RichText* fields are covered in more detail {ref}` later in this manual <richtext-label> ` .
143- :::
138+ The extra traversal to `details/output` is necessary because the ` RichText` field actually stores a ` RichTextValue` object that contains not only the raw text as entered by the user, but also a MIME type (for example, `text/html`) and the rendered output text.
139+ ` RichText` fields are covered in more detail {ref}`later in this manual <richtext-label>`.
140+ ```
144141
145- The view for ` Presenter ` is even simpler:
142+ The view for ` Presenter ` is the following.
146143
147144``` xml
148145<configure
149146 xmlns =" http://namespaces.zope.org/zope"
150147 xmlns : browser =" http://namespaces.zope.org/browser" >
151148
152- ...
153-
154149 <browser : page
155150 name =" view"
156151 for =" example.conference.program.IPresenter"
@@ -161,7 +156,7 @@ The view for `Presenter` is even simpler:
161156</configure >
162157```
163158
164- The template, in ` templates/presenterview.pt ` , is similar to the previous template:
159+ The template in {file} ` templates/presenterview.pt ` is similar to the previous template.
165160
166161``` html
167162<html xmlns =" http://www.w3.org/1999/xhtml" xml:lang =" en"
@@ -200,39 +195,37 @@ The template, in `templates/presenterview.pt`, is similar to the previous templa
200195Obviously, these views are very basic.
201196Much more interesting views could be created by putting a little more work into the templates.
202197
203- You should also realise that you can create any type of view using this technique.
204- Your view does not have to be related to a particular content type, even.
205- You could set the context to ` Interface ` , for example, to make a view that’s available on all types.
198+ You should also realize that you can create any type of view using this technique.
199+ Your view does not have to be related to a particular content type.
200+ You could set the context to ` Interface ` , for example, to make a view that's available on all types.
201+
206202
207203## Display view
208204
209- ** Using display widgets in your views**
205+ In this section, we describe how to use display widgets in your views.
210206
211207In the previous section, we created a browser view.
212208This kind of view is the most common.
213- Sometimes we want to make use of the widgets and information in the type’ s schema more directly.
214- For example to invoke transforms or re-use more complex HTML.
209+ Sometimes we want to make use of the widgets and information in the type' s schema more directly.
210+ For example to invoke transforms or reuse more complex HTML.
215211
216- To do this, you can use a * display view* .
217- This is really just a view base class that knows about the schema of a type.
218- We will use an example in ` session.py ` , with a template in ` templates/sessionview.pt ` .
212+ To do this, you can use a display view.
213+ This is a view base class that knows about the schema of a type.
214+ We will use an example in {file} ` session.py ` , with a template in {file} ` templates/sessionview.pt ` .
219215
220- :::{note}
221- * Display view* involve the same type of overhead as add- and edit-forms.
222- If you have complex content type with many behaviors, fieldsets and
223- widget hints, you may notice a slow-down. This can be a problem
224- on high volume sites.
225- :::
216+ ``` {note}
217+ *Display views* involve the same type of overhead as add and edit forms.
218+ If you have complex content type with many behaviors, fieldsets, and widget hints, you may notice a slow down.
219+ This can be a problem on high volume sites.
220+ ```
226221
227- The new view class is pretty much the same as before, except that we derive from ` plone.dexterity.browser.view.DefaultView ` :
222+ The new view class is pretty much the same as before, except that we derive from ` plone.dexterity.browser.view.DefaultView ` .
228223
229224``` xml
230225<configure
231226 xmlns =" http://namespaces.zope.org/zope"
232227 xmlns : browser =" http://namespaces.zope.org/browser" >
233228
234- ...
235-
236229 <browser : page
237230 name =" view"
238231 for =" example.conference.program.ISession"
@@ -251,33 +244,28 @@ class SessionView(DefaultView):
251244 pass
252245```
253246
254- This gives our view a few extra properties that we can use in the template:
247+ This gives our view a few extra properties that we can use in the template.
255248
256249` view.w `
257-
258- : a dictionary of all the display widgets, keyed by field names.
259- For fields provided by behaviors, that is usually prefixed with the behavior interface name (` IBehaviorInterface.field_name ` ).
260- For the default schema, unqualified names apply.
250+ : A dictionary of all the display widgets, keyed by field names.
251+ For fields provided by behaviors, that is usually prefixed with the behavior interface name (` IBehaviorInterface.field_name ` ).
252+ For the default schema, unqualified names apply.
261253
262254` view.widgets `
263-
264- : contains a list of widgets in schema order for the default fieldset.
255+ : Contains a list of widgets in schema order for the default fieldset.
265256
266257` view.groups `
267-
268- : contains a list of fieldsets in fieldset order.
258+ : Contains a list of fieldsets in fieldset order.
269259
270260` view.fieldsets `
271-
272- : contains a dictionary mapping fieldset name to fieldset.
261+ : Contains a dictionary mapping fieldset name to fieldset.
273262
274263` widgets `
275-
276- : On a fieldset (group), you can access a ` widgets ` list to get widgets in that fieldset.
264+ : On a fieldset (group), you can access a ` widgets ` list to get widgets in that fieldset.
277265
278266The ` w ` dict is the most commonly used.
279267
280- The ` templates/sessionview.pt ` template contains the following:
268+ The {file} ` templates/sessionview.pt ` template contains the following code.
281269
282270``` html
283271<html xmlns =" http://www.w3.org/1999/xhtml" xml:lang =" en"
@@ -305,7 +293,5 @@ The `templates/sessionview.pt` template contains the following:
305293</html >
306294```
307295
308- Notice how we use expressions like ` view/w/details/render ` (where ` details ` is the field name) to get the rendering of a widget.
296+ Notice how we use expressions such as ` view/w/details/render ` (where ` details ` is the field name) to get the rendering of a widget.
309297Other properties include ` __name__ ` , the field name, and ` label ` , the field title.
310-
311- [ z3c.form ] : http://pypi.python.org/pypi/z3c.form
0 commit comments