src/source/dev_guide/custom-skin.rst
branchdoc-dc
changeset 142 5a82a9a2ea46
parent 139 d632f8d6140b
child 148 337b4e28c11f
equal deleted inserted replaced
141:9ab9f762abed 142:5a82a9a2ea46
   205 Add settings interface to the renderer `settings_interface = IPhotoRendererSettings`
   205 Add settings interface to the renderer `settings_interface = IPhotoRendererSettings`
   206 
   206 
   207 .. tip::
   207 .. tip::
   208     When a setting_interface is associated to a renderer, you can access to `settings` attributes through the template
   208     When a setting_interface is associated to a renderer, you can access to `settings` attributes through the template
   209 
   209 
       
   210 
       
   211 .. _templatehowto:
       
   212 
       
   213 How to define or change a template for a specific skin?
       
   214 =======================================================
       
   215 
       
   216 Override the default template for a renderer
       
   217 --------------------------------------------
       
   218 
       
   219 If you want to modify the template for a particular rendering mode, you can use the function :py:func:`override_template`
       
   220 
       
   221 .. code-block:: python
       
   222 
       
   223 	from pyams_template.template import override_template
       
   224 
       
   225 	from my_website.skin.public.layer import ICustomLayer
       
   226 	from pyams_default_theme.component.keynumber.portlet import KeyNumberPortletHorizontalRenderer
       
   227 
       
   228 
       
   229 	override_template(context=KeyNumberPortletHorizontalRenderer,
       
   230 					template="templates/keynumber-horizontal.pt",
       
   231 					layer=ICustomLayer
       
   232 					)
       
   233 
       
   234 
       
   235 This new template can be applied to a particular :ref:`Skin <skinhowto>` by specifying on which layer to use this renderer
       
   236 *(ex: layer=IMyWebsiteLayer)*
       
   237 
       
   238 
       
   239 
       
   240 Redefine the default template for a renderer
       
   241 --------------------------------------------
       
   242 
       
   243 You must redefine an adapter to add new variables or static resources for your new template,
       
   244 
       
   245 .. code-block:: python
       
   246 
       
   247 	# import interfaces
       
   248 	from my_website.skin.public.layer import ICustomLayer
       
   249 
       
   250 	from pyams_content.component.keynumber.portlet.interfaces import IKeyNumberPortletSettings
       
   251 	from pyams_portal.interfaces import IPortletRenderer, IPortalContext
       
   252 
       
   253 	# import packages
       
   254 	from my_website.skin.public import my_carousel_init ,my_carousel_animation
       
   255 
       
   256 	from pyams_default_theme.component.keynumber.portlet import KeyNumberPortletHorizontalRenderer
       
   257 	from pyams_template.template import template_config
       
   258 	from pyams_utils.adapter import adapter_config
       
   259 	from zope.interface import Interface
       
   260 
       
   261 
       
   262 	@adapter_config(context=(IPortalContext, IBaseLayer, Interface, IKeyNumberPortletSettings),
       
   263 	                provides=IPortletRenderer)
       
   264 	@template_config(template='templates/keynumber-horizontal.pt', layer=ICustomLayer)
       
   265 	class MyCustomKeyNumberPortletHorizontalRenderer(KeyNumberPortletHorizontalRenderer):
       
   266 		"""Key numbers portlet horizontal renderer"""
       
   267 
       
   268 		resources = (my_carousel_init, my_carousel_animation)
       
   269 
       
   270 
       
   271 The attribute :py:attr:`resources` is used to load in the template static resources. The application will automatically
       
   272 integrate resource content when the template is calling.