src/source/developer_guide/howto-template.rst
branchdoc-dc
changeset 111 097b0c025eec
parent 110 d7dd088ed557
child 112 49e4432c0a1d
equal deleted inserted replaced
110:d7dd088ed557 111:097b0c025eec
     1 .. _templatehowto:
       
     2 
       
     3 
       
     4 How to define or change a template for a specific skin?
       
     5 =======================================================
       
     6 
       
     7 Override the default template for a renderer
       
     8 --------------------------------------------
       
     9 
       
    10 If you want to modify the template for a particular rendering mode, you can use the function :py:func:`override_template`
       
    11 
       
    12 .. code-block:: python
       
    13 
       
    14 	from pyams_template.template import override_template
       
    15 
       
    16 	from my_website.skin.public.layer import ICustomLayer
       
    17 	from pyams_default_theme.component.keynumber.portlet import KeyNumberPortletHorizontalRenderer
       
    18 
       
    19 
       
    20 	override_template(context=KeyNumberPortletHorizontalRenderer,
       
    21 					template="templates/keynumber-horizontal.pt",
       
    22 					layer=ICustomLayer
       
    23 					)
       
    24 
       
    25 
       
    26 This new template can be applied to a particular :ref:`Skin <skinhowto>` by specifying on which layer to use this renderer
       
    27 *(ex: layer=IMyWebsiteLayer)*
       
    28 
       
    29 
       
    30 
       
    31 Redefine the default template for a renderer
       
    32 --------------------------------------------
       
    33 
       
    34 You must redefine an adapter to add new variables or static resources for your new template,
       
    35 
       
    36 .. code-block:: python
       
    37 
       
    38 	# import interfaces
       
    39 	from my_website.skin.public.layer import ICustomLayer
       
    40 
       
    41 	from pyams_content.component.keynumber.portlet.interfaces import IKeyNumberPortletSettings
       
    42 	from pyams_portal.interfaces import IPortletRenderer, IPortalContext
       
    43 
       
    44 	# import packages
       
    45 	from my_website.skin.public import my_carousel_init ,my_carousel_animation
       
    46 
       
    47 	from pyams_default_theme.component.keynumber.portlet import KeyNumberPortletHorizontalRenderer
       
    48 	from pyams_template.template import template_config
       
    49 	from pyams_utils.adapter import adapter_config
       
    50 	from zope.interface import Interface
       
    51 
       
    52 
       
    53 	@adapter_config(context=(IPortalContext, IBaseLayer, Interface, IKeyNumberPortletSettings),
       
    54 	                provides=IPortletRenderer)
       
    55 	@template_config(template='templates/keynumber-horizontal.pt', layer=ICustomLayer)
       
    56 	class MyCustomKeyNumberPortletHorizontalRenderer(KeyNumberPortletHorizontalRenderer):
       
    57 		"""Key numbers portlet horizontal renderer"""
       
    58 
       
    59 		resources = (my_carousel_init, my_carousel_animation)
       
    60 
       
    61 
       
    62 The attribute :py:attr:`resources` is used to load in the template static resources. The application will automatically
       
    63 integrate resource content when the template is calling.