# HG changeset patch # User Damien Correia # Date 1534263962 -7200 # Node ID 8e05d726d4ad522fcce573b1639a137f86f0671f # Parent 92e2a6a91a966006440002f83a730f6caa937b9c# Parent edcd71304333d8d571ccf642f0019d1c65679caf Merge default diff -r 92e2a6a91a96 -r 8e05d726d4ad src/source/howto-template.rst --- a/src/source/howto-template.rst Thu Jun 28 12:05:42 2018 +0200 +++ b/src/source/howto-template.rst Tue Aug 14 18:26:02 2018 +0200 @@ -1,6 +1,63 @@ .. _templatehowto: -How to create a new template? -============================= +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 ` 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.