Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit a7e8ad8

Browse files
author
Ben Glassman
committed
Add documentation for cmf_seo_update_metadata twig function
1 parent d392bcf commit a7e8ad8

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

bundles/map.rst.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ library or they introduce a complete new concept.
7272
* :doc:`seo/seo_aware`
7373
* :doc:`seo/extractors`
7474
* :doc:`seo/configuration`
75+
* :doc:`seo/twig`
7576

7677
* :doc:`tree_browser/index`
7778

bundles/seo/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ SeoBundle
99
extractors
1010
sitemap
1111
configuration
12+
twig

bundles/seo/introduction.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,16 @@ key in ``cmf_seo.content_key``.
137137
You may also want to disable this listener when implementing your own mechanism
138138
to extract SEO information.
139139

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+
140150
Extracting Metadata
141151
~~~~~~~~~~~~~~~~~~~
142152

bundles/seo/twig.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 %}

0 commit comments

Comments
 (0)