--- a/src/pyams_default_theme/features/header/skin/__init__.py Tue Jul 03 14:33:51 2018 +0200
+++ b/src/pyams_default_theme/features/header/skin/__init__.py Tue Jul 03 14:34:19 2018 +0200
@@ -17,6 +17,7 @@
# import interfaces
from pyams_content.component.association.interfaces import IAssociationInfo
+from pyams_content.component.links.interfaces import IInternalLink
from pyams_content.features.header.interfaces import IHeaderTarget, IHeaderRenderer, IHeaderSettings, \
IHeaderRendererSettings
from pyams_default_theme.features.header.interfaces import ISimpleHeaderRendererSettings
@@ -27,6 +28,7 @@
from pyams_default_theme.features.header import SimpleHeaderRendererSettings
from pyams_template.template import template_config
from pyams_utils.adapter import adapter_config
+from pyramid.location import lineage
from pyams_default_theme import _
@@ -51,10 +53,21 @@
settings_key = 'PyAMS::simple'
settings_interface = ISimpleHeaderRendererSettings
+ def update(self):
+ super(SimpleHeaderRenderer, self).update()
+ self.request.annotations['REQUEST_PATH'] = list(lineage(self.request.context))
+
@staticmethod
def get_link_info(link):
return IAssociationInfo(link)
+ def is_active(self, link):
+ if IInternalLink.providedBy(link):
+ target = link.get_target()
+ if target is not None:
+ return target in self.request.annotations['REQUEST_PATH']
+ return False
+
@adapter_config(context=SimpleHeaderRenderer, provides=IHeaderRendererSettings)
def simple_header_renderer_settings_factory(context):
--- a/src/pyams_default_theme/features/header/skin/templates/simple-header.pt Tue Jul 03 14:33:51 2018 +0200
+++ b/src/pyams_default_theme/features/header/skin/templates/simple-header.pt Tue Jul 03 14:34:19 2018 +0200
@@ -9,16 +9,23 @@
</tal:if>
<tal:if define="logo settings.logo"
condition="logo">
- <img class="logo"
- tal:define="src extension:absolute_url(settings.logo, '++thumb++200x200')"
- tal:attributes="src string:${src}?_=${extension:timestamp(logo)}" />
+ <a href="/" title="Back home" i18n:attributes="title">
+ <img class="logo"
+ tal:define="src extension:absolute_url(settings.logo, '++thumb++200x200')"
+ tal:attributes="src string:${src}?_=${extension:timestamp(logo)}" />
+ </a>
</tal:if>
</div>
- <tal:loop repeat="link settings.tabs.get_visible_items()">
- <a tal:define="info view.get_link_info(link);
- href link.get_url(request)"
- tal:condition="href"
- tal:content="info.user_title"
- tal:attributes="href href">Link</a><br />
- </tal:loop>
+ <ul class="nav nav-tabs" role="tablist">
+ <tal:loop repeat="link settings.tabs.get_visible_items()">
+ <li role="presentation"
+ tal:attributes="class 'active' if view.is_active(link) else ''">
+ <a tal:define="info view.get_link_info(link);
+ href link.get_url(request);"
+ tal:condition="href"
+ tal:content="info.user_title"
+ tal:attributes="href href">Link</a>
+ </li>
+ </tal:loop>
+ </ul>
</div>