src/source/howto-template.rst
changeset 99 b2be9a32f3fc
child 104 942151432421
equal deleted inserted replaced
-1:000000000000 99:b2be9a32f3fc
       
     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.