diff -r 000000000000 -r b2be9a32f3fc src/source/howto-template.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/source/howto-template.rst Thu Dec 06 08:24:10 2018 +0100 @@ -0,0 +1,63 @@ +.. _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 ` 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.