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
Layers allow you to activate different code paths and modules depending on
14
-
the external configuration.
14
+
Layers allow you to activate different code paths and modules depending on the external configuration.
15
+
Layers are useful in the following scenarios.
15
16
16
-
Examples:
17
-
18
-
- Code belonging to a theme is only active when that theme has been selected.
19
-
- Mobile browsing code is only active when the site is being browsed on a
20
-
mobile phone.
17
+
- Code belonging to a theme is only active when that theme has been selected.
18
+
- Mobile browsing code is only active when the site is being browsed on a mobile phone.
21
19
22
20
Layers are marker interfaces applied to the {term}`HTTPRequest` object.
23
-
They are usually used in conjunction with {term}`ZCML` directives to
24
-
dynamically activate various parts
25
-
of the configuration (theme files, add-on product functionality).
21
+
They are usually used in conjunction with {term}`ZCML` directives to dynamically activate various parts of the configuration, such as theme files or add-on product functionality.
22
+
23
+
Layers ensure that only one add-on product can override the specific Plone instance functionality in your site at a time, while still allowing you to have possibly conflicting add-on products in your buildout and ZCML.
24
+
Multiple Plone site instances can share the same ZCML and code files.
25
+
26
+
Many ZCML directives take the optional `layer` parameter.
27
+
See example [resourceDirectory](http://apidoc.zope.org/++apidoc++/ZCML/http_co__sl__sl_namespaces.zope.org_sl_browser/resourceDirectory/index.html).
26
28
27
-
Layers ensure that only one add-on product can override the specific Plone
28
-
instance functionality in your site at a time, while still allowing you
29
-
to have possibly conflicting add-on products in your buildout and
30
-
ZCML. Remember that multiple Plone site instances can share
31
-
the same ZCML and code files.
29
+
Layers are activated when an add-on product is installed or a certain theme is activated.
32
30
33
-
Many ZCML directives take the optional `layer` parameter. See example,
Layers are activated when an add-on product is installed or a certain
37
-
theme is picked.
32
+
(classic-ui-using-layers-label)=
38
33
39
34
## Using layers
40
35
41
-
Some ZCML directives for example: `browser:page`take a `layer` attribute.
36
+
Some ZCML directives take a `layer` attribute, such as `browser:page`.
42
37
43
38
Given the following:
44
39
45
-
- A layer interface defined in Python code:`plonetheme.yourthemename.interfaces.IThemeSpecific`
46
-
- Your add-on or theme package installed through add-on product installer on your site instance
40
+
-A layer interface defined in Python code,`plonetheme.yourthemename.interfaces.IThemeSpecific`.
41
+
-Your add-on or theme package installed through the add-on product installer on your site instance.
47
42
48
-
then views and viewlets from your product can be enabled on the site
49
-
instance using the following ZCML:
43
+
Then views and viewlets from your product can be enabled on the site instance using the following ZCML:
50
44
51
-
```
45
+
```xml
52
46
<!-- Site actions override in YourTheme -->
53
47
<browser:viewlet
54
48
name="plone.site_actions"
@@ -59,75 +53,87 @@ instance using the following ZCML:
59
53
/>
60
54
```
61
55
56
+
57
+
(classic-ui-unconditional-overrides-label)=
58
+
62
59
### Unconditional overrides
63
60
64
-
If you want to override a view or a viewlet unconditionally for all sites
65
-
without the add-on product installer
66
-
support you need to use `overrides.zcml`.
61
+
If you want to override a view or a viewlet unconditionally for all sites without the add-on product installer support, you need to use `overrides.zcml`.
62
+
63
+
64
+
(classic-ui-creating-a-layer-label)=
67
65
68
66
## Creating a layer
69
67
68
+
69
+
(classic-ui-theme-layer-label)=
70
+
70
71
### Theme layer
71
72
72
-
Theme layers can be created via the following steps:
73
+
Theme layers can be created through the following steps.
73
74
74
-
1. Subclass an interface from `IDefaultPloneLayer`:
75
+
1.Subclass an interface from `IDefaultPloneLayer`:
75
76
76
-
```
77
-
from plone.theme.interfaces import IDefaultPloneLayer
77
+
```python
78
+
from plone.theme.interfaces import IDefaultPloneLayer
78
79
79
-
class IThemeSpecific(IDefaultPloneLayer):
80
-
"""Marker interface that defines a Zope 3 skin layer bound to a Skin
81
-
Selection in portal_skins.
82
-
If you need to register a viewlet only for the "YourSkin"
83
-
skin, this is the interface that must be used for the layer attribute
84
-
in YourSkin/browser/configure.zcml.
85
-
"""
86
-
```
87
80
88
-
2. Register it in ZCML. The name must match the theme name.
81
+
classIThemeSpecific(IDefaultPloneLayer):
82
+
"""
83
+
Marker interface that defines a Zope 3 skin layer bound to a Skin
84
+
Selection in portal_skins.
85
+
If you need to register a viewlet only for the "YourSkin"
86
+
skin, this is the interface that must be used for the layer attribute
3. Register and set your theme as the default theme in `profiles/default/skins.xml`. Theme layers require that they are set as the default theme and not just activated on your Plone site. Example:
You can also use layers to modify the behavior of plone or another Add-on.
177
+
You can also use layers to modify the behavior of Ploneor another add-on.
171
178
172
-
To make sure that your own view is used, your Layer must be more specific than the layer where original view is registered.
179
+
To make sure that your own view is used, your layer must be more specific than the layer where the original view is registered.
173
180
174
-
For example, some z3cform things register their views on the `IPloneFormLayer` from plone.app.z3cform.interfaces.
181
+
For example, some `z3cform` things register their views on the `IPloneFormLayer`from`plone.app.z3cform.interfaces`.
175
182
176
-
If you want to override the ploneform-macros view that is registered on the `IPloneFormLayer`, your own Layer must be a subclass of IPloneFormLayer.
183
+
If you want to override the `ploneform-macros` view that is registered on the `IPloneFormLayer`, your own layer must be a subclass of `IPloneFormLayer`.
177
184
178
-
If a view does not declare a specific Layer, it becomes registered on the `IDefaultBrowserLayer` from zope.publisher.interfaces.browser.IDefaultBrowserLayer.
185
+
If a view does not declare a specific layer, it becomes registered on the `IDefaultBrowserLayer`from`zope.publisher.interfaces.browser.IDefaultBrowserLayer`.
179
186
180
187
188
+
(classic-ui-manual-layers-label)=
189
+
181
190
### Manual layers
182
191
183
-
Apply your layer to the {term}`HTTPRequest` in the `before_traverse` hook or
184
-
before you call the code which looks up the interfaces.
192
+
Apply your layer to the {term}`HTTPRequest`in the `before_traverse` hook, or before you call the code which looks up the interfaces.
185
193
186
-
In the example below we turn on a layer for the request which is later
187
-
checked by the rendering code.
194
+
In the example below, we turn on a layer for the request, which is later checked by the rendering code.
188
195
This way some pages can ask for special View/Viewlet rendering.
189
196
190
-
Example:
191
-
192
-
```
197
+
```python
193
198
# Defining layer
194
199
195
200
from zope.publisher.interfaces.browser import IBrowserRequest
196
201
197
202
class INoHeaderLayer(IBrowserRequest):
198
-
""" When applied to HTTP request object, header animations or images are not rendered on this.
203
+
""" When applied to HTTP request object, header animations
204
+
or images are not rendered on this.
199
205
200
-
If this layer is on request do not render header images.
206
+
If this layer is on request, do not render header images.
201
207
This allows uncluttered editing of header animations and images.
202
208
"""
203
209
@@ -219,42 +225,48 @@ class EditHeaderAnimationsView(FormWrapper):
0 commit comments