This repository was archived by the owner on Sep 16, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +52
-0
lines changed Expand file tree Collapse file tree 4 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -72,6 +72,7 @@ library or they introduce a complete new concept.
72
72
* :doc:` seo/seo_aware`
73
73
* :doc:` seo/extractors`
74
74
* :doc:` seo/configuration`
75
+ * :doc:` seo/twig`
75
76
76
77
* :doc:` tree_browser/index`
77
78
Original file line number Diff line number Diff line change @@ -9,3 +9,4 @@ SeoBundle
9
9
extractors
10
10
sitemap
11
11
configuration
12
+ twig
Original file line number Diff line number Diff line change @@ -137,6 +137,16 @@ key in ``cmf_seo.content_key``.
137
137
You may also want to disable this listener when implementing your own mechanism
138
138
to extract SEO information.
139
139
140
+ The Twig Extension
141
+ ~~~~~~~~~~~~~~~~~~
142
+
143
+ .. versionadded :: 1.2
144
+ The twig extension was added in SeoBundle 1.2.
145
+
146
+ This bundle provides a twig function ``cmf_seo_update_metadata ``
147
+ which lets you populate the seo page from an object.
148
+ For details on using the twig extension, read :doc: `twig `.
149
+
140
150
Extracting Metadata
141
151
~~~~~~~~~~~~~~~~~~~
142
152
Original file line number Diff line number Diff line change
1
+ Setting Seo Metadata from Twig
2
+ ==============================
3
+
4
+ .. versionadded :: 1.2
5
+ The twig extension was added in SeoBundle 1.2.
6
+
7
+ This bundle provides a twig function ``cmf_seo_update_metadata ``
8
+ which lets you populate the seo page from an object.
9
+ For details on how populating the SEO page works, read :doc: `introduction `.
10
+
11
+ You must call this function in your twig template before the calls to
12
+ ``sonata_seo_title `` and ``sonata_seo_metadatas `` functions. The
13
+ recommended set up for this is to create a metadata block in your
14
+ base twig template and override it in a sub template, calling
15
+ ``cmf_seo_update_metadata `` before calling ``parent() ``.
16
+
17
+ .. code-block :: html+jinja
18
+
19
+ <!-- app/Resources/views/base.html.twig -->
20
+ <!DOCTYPE html>
21
+ <html>
22
+ <head>
23
+ {% block metadata %}
24
+ {{ sonata_seo_title() }}
25
+
26
+ {{ sonata_seo_metadatas() }}
27
+ {% endblock metadata %}
28
+ </head>
29
+ <body>
30
+ <p>Some page body.</p>
31
+ </body>
32
+ </html>
33
+
34
+ <!-- app/Resources/views/Blog/post.html.twig -->
35
+ {% extends 'base.html.twig' %}
36
+
37
+ {% block metadata %}
38
+ {{ cmf_seo_update_metadata(post) }}
39
+ {{ parent() }}
40
+ {% endblock metadata %}
You can’t perform that action at this time.
0 commit comments