22 .. code-block:: python |
22 .. code-block:: python |
23 :linenos: |
23 :linenos: |
24 |
24 |
25 # New custom contact paragraph renderer |
25 # New custom contact paragraph renderer |
26 |
26 |
27 @adapter_config(name='custom', context=(IContactParagraph, IPyAMSLayer), provides=IContentRenderer) |
27 @adapter_config(name='custom', context=(IContactParagraph, IPyAMSLayer), provides=ISharedContentRenderer) |
28 @template_config(template='templates/contact-custom.pt', layer=IPyAMSLayer) |
28 @template_config(template='templates/contact-custom.pt', layer=IPyAMSLayer) |
29 class ContactParagraphCustomRenderer(ContactParagraphDefaultRenderer): |
29 class ContactParagraphCustomRenderer(ContactParagraphDefaultRenderer): |
30 """Context paragraph custom renderer""" |
30 """Context paragraph custom renderer""" |
31 |
31 |
32 label = _("Custom contact renderer") |
32 label = _("Custom contact renderer") |
33 settings_interface = IContactParagraphDefaultRendererSettings |
33 settings_interface = IContactParagraphDefaultRendererSettings |
34 |
34 |
35 |
35 |
36 In this example, we have defined an adapter named 'custom' with :py:class:`IContactParagraph`, |
36 In this example, we have defined an adapter named 'custom' with :py:class:`IContactParagraph`, |
37 :py:class:`IPyAMSLayer` as context and provides :py:class:`IContentRenderer` interface. |
37 :py:class:`IPyAMSLayer` as context and provides :py:class:`ISharedContentRenderer` interface. |
38 |
38 |
39 Using ``@template_config()`` decorator, the renderer will be displayed in html container according to the template |
39 Using ``@template_config()`` decorator, the renderer will be displayed in html container according to the template |
40 |
40 |
41 The new renderer inherit of :py:class:`ContactParagraphDefaultRenderer`, have a new **label** (line 8) |
41 The new renderer inherit of :py:class:`ContactParagraphDefaultRenderer`, have a new **label** (line 8) |
42 and is associated an **settings_interface** (line 9) |
42 and is associated an **settings_interface** (line 9) |
48 |
48 |
49 |
49 |
50 2. Create a new Renderer from scratch |
50 2. Create a new Renderer from scratch |
51 ------------------------------------- |
51 ------------------------------------- |
52 |
52 |
53 We can define a new settings interface for the renderer, to do that we start by creating an interface |
53 We can define a new settings for the renderer, to do that we start by creating an interface: |
54 |
54 |
55 |
55 |
56 a) Create setting interface for the renderer |
56 a) Create setting interface for the renderer |
57 """""""""""""""""""""""""""""""""""""""""""" |
57 """""""""""""""""""""""""""""""""""""""""""" |
58 |
58 |
115 c) Create an adapter for the render interface |
115 c) Create an adapter for the render interface |
116 """"""""""""""""""""""""""""""""""""""""""""" |
116 """"""""""""""""""""""""""""""""""""""""""""" |
117 |
117 |
118 .. code-block:: python |
118 .. code-block:: python |
119 |
119 |
120 @adapter_config(context=(IContactParagraph, IPyAMSLayer), provides=IContentRenderer) |
120 @adapter_config(context=(IContactParagraph, IPyAMSLayer), provides=ISharedContentRenderer) |
121 @template_config(template='templates/contact-custom.pt', layer=IPyAMSLayer) |
121 @template_config(template='templates/contact-custom.pt', layer=IPyAMSLayer) |
122 class PhotoRenderer(BaseContentRenderer): |
122 class PhotoRenderer(BaseContentRenderer): |
123 """Context paragraph custom renderer""" |
123 """Context paragraph custom renderer""" |
124 |
124 |
125 label = _("Custom contact renderer") |
125 label = _("Custom contact renderer") |