use metas to render page title
authorThierry Florac <thierry.florac@onf.fr>
Thu, 05 Jul 2018 12:32:22 +0200
changeset 78 767f9ec890f4
parent 77 0c08a8d9496d
child 79 c849d079a782
use metas to render page title
src/pyams_zmi/interfaces/templates/admin-layout.pt
src/pyams_zmi/metas.py
--- a/src/pyams_zmi/interfaces/templates/admin-layout.pt	Mon Jun 11 16:03:58 2018 +0200
+++ b/src/pyams_zmi/interfaces/templates/admin-layout.pt	Thu Jul 05 12:32:22 2018 +0200
@@ -7,9 +7,6 @@
 <head>
 	<tal:var replace="structure extension:metas" />
 
-	<title tal:attributes="data-ams-title-prefix config.get_title_prefix(request)"
-		   tal:content="config.title"></title>
-
 	<tal:if define="icon config.icon | nothing; url extension:absolute_url(icon);" condition="icon">
 		<!-- Favorite icon -->
 		<link rel="shortcut icon" tal:attributes="href url" type="image/x-icon">
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_zmi/metas.py	Thu Jul 05 12:32:22 2018 +0200
@@ -0,0 +1,38 @@
+#
+# Copyright (c) 2008-2018 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+
+__docformat__ = 'restructuredtext'
+
+
+# import standard library
+
+# import interfaces
+from pyams_skin.interfaces.configuration import IBackOfficeConfiguration
+from pyams_skin.interfaces.metas import IHTMLContentMetas
+from pyams_zmi.layer import IAdminLayer
+
+# import packages
+from pyams_skin.metas import HTMLTagMeta
+from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter
+from zope.interface import Interface
+
+
+@adapter_config(name='title', context=(Interface, IAdminLayer, Interface), provides=IHTMLContentMetas)
+class TitleMetasAdapter(ContextRequestViewAdapter):
+    """Title metas adapter"""
+
+    order = 1
+
+    def get_metas(self):
+        config = IBackOfficeConfiguration(self.request.root)
+        yield HTMLTagMeta('title', config.title,
+                          **{'data-ams-title-prefix': config.get_title_prefix(self.request)})