src/source/dev_guide/custom-skin.rst
branchdoc-dc
changeset 142 5a82a9a2ea46
parent 139 d632f8d6140b
child 148 337b4e28c11f
--- a/src/source/dev_guide/custom-skin.rst	Fri Dec 21 15:52:29 2018 +0100
+++ b/src/source/dev_guide/custom-skin.rst	Fri Dec 21 17:28:34 2018 +0100
@@ -207,3 +207,66 @@
 .. tip::
     When a setting_interface is associated to a renderer, you can access to `settings` attributes through the template
 
+
+.. _templatehowto:
+
+How to define or change a template for a specific skin?
+=======================================================
+
+Override the default template for a renderer
+--------------------------------------------
+
+If you want to modify the template for a particular rendering mode, you can use the function :py:func:`override_template`
+
+.. code-block:: python
+
+	from pyams_template.template import override_template
+
+	from my_website.skin.public.layer import ICustomLayer
+	from pyams_default_theme.component.keynumber.portlet import KeyNumberPortletHorizontalRenderer
+
+
+	override_template(context=KeyNumberPortletHorizontalRenderer,
+					template="templates/keynumber-horizontal.pt",
+					layer=ICustomLayer
+					)
+
+
+This new template can be applied to a particular :ref:`Skin <skinhowto>` by specifying on which layer to use this renderer
+*(ex: layer=IMyWebsiteLayer)*
+
+
+
+Redefine the default template for a renderer
+--------------------------------------------
+
+You must redefine an adapter to add new variables or static resources for your new template,
+
+.. code-block:: python
+
+	# import interfaces
+	from my_website.skin.public.layer import ICustomLayer
+
+	from pyams_content.component.keynumber.portlet.interfaces import IKeyNumberPortletSettings
+	from pyams_portal.interfaces import IPortletRenderer, IPortalContext
+
+	# import packages
+	from my_website.skin.public import my_carousel_init ,my_carousel_animation
+
+	from pyams_default_theme.component.keynumber.portlet import KeyNumberPortletHorizontalRenderer
+	from pyams_template.template import template_config
+	from pyams_utils.adapter import adapter_config
+	from zope.interface import Interface
+
+
+	@adapter_config(context=(IPortalContext, IBaseLayer, Interface, IKeyNumberPortletSettings),
+	                provides=IPortletRenderer)
+	@template_config(template='templates/keynumber-horizontal.pt', layer=ICustomLayer)
+	class MyCustomKeyNumberPortletHorizontalRenderer(KeyNumberPortletHorizontalRenderer):
+		"""Key numbers portlet horizontal renderer"""
+
+		resources = (my_carousel_init, my_carousel_animation)
+
+
+The attribute :py:attr:`resources` is used to load in the template static resources. The application will automatically
+integrate resource content when the template is calling.