@@ -32,6 +32,15 @@ Both the CmfSeoBundle and SonataSeoBundle must be registered in the
32
32
Usage
33
33
~~~~~
34
34
35
+ SEO data tracks some or all of the following:
36
+
37
+ * The title;
38
+ * The meta keywords;
39
+ * The meta description;
40
+ * The original URL (when more than one URL contains the same content).
41
+ * Anything else that uses the ``<meta> `` tag with the ``property ``, ``name ``
42
+ or ``http-equiv `` type (e.g. Open Graph data).
43
+
35
44
The simplest use of this bundle would be to just set some configuration to the
36
45
``sonata_seo `` configuration section and use the twig helper in your templates.
37
46
@@ -62,8 +71,12 @@ The simplest use of this bundle would be to just set some configuration to the
62
71
),
63
72
),
64
73
));
65
-
66
- The only thing to do now is to use the twig helper in your templates:
74
+
75
+ This sets default values for the ``SeoPage `` value object. You can later update
76
+ that object with more precise information. It is available as service
77
+ ``sonata.seo.page.default ``.
78
+
79
+ To render the information, use the following twig functions in your templates:
67
80
68
81
.. code-block :: html+jinja
69
82
@@ -80,54 +93,73 @@ The only thing to do now is to use the twig helper in your templates:
80
93
</body>
81
94
</html>
82
95
83
- This will render a page with the default title ("Page's default title") as
84
- title element. The information defined for description and keywords will go
85
- into the correct metatags .
96
+ This will render the last title set on the `` SeoPage `` ("Page's default title"
97
+ if you did not add calls to the value object in your code). The information
98
+ added for description and keywords will render as `` <meta> `` HTML tags .
86
99
87
100
.. seealso ::
88
101
89
102
To get a deeper look into the SonataSeoBundle, you should visit the
90
103
`Sonata documentation `_.
91
104
92
- Using SeoMetadata
93
- -----------------
105
+ Using the CmfSeoBundle
106
+ ----------------------
94
107
95
108
The basic example shown above works perfectly without the CmfSeoBundle. The
96
- CmfSeoBundle provides more extension points to configure the SEO data with
97
- data from the document (e.g. a ``StaticContent `` document). This is done by
98
- using SEO metadata. This is SEO data which will be used for a particular
99
- document. This metadata can hold:
109
+ CmfSeoBundle provides extension points to extract the SEO data from
110
+ content documents, e.g. a ``StaticContent ``, along with utility systems
111
+ to automatically extract the information.
100
112
101
- * The title;
102
- * The meta keywords;
103
- * The meta description;
104
- * The original URL (when more than one URL contains the same content).
105
- * Anything else that uses the ``<meta> `` tag with the ``property ``, ``name ``
106
- or ``http-equiv `` type (e.g. Open Graph data).
113
+ The process is:
114
+
115
+ 1. The content listener checks for a document in the request
116
+ 2. It invokes ``SeoPresentationInterface::updateSeoPage ``
117
+ 3. The presentation checks of the document provides a ``SeoMetadata `` value
118
+ object and runs the metadata extractors.
119
+ 4. The presentation updates the Sonata ``SeoPage `` with the gathered meta data.
120
+
121
+ .. _bundles-seo-content-listener :
107
122
108
- The content object is retrieved from the request attributes. By default, it
109
- uses the ``DynamicRouter::CONTENT_KEY `` constant when the
110
- :doc: `RoutingBundle <../routing/introduction >` is installed. To change this,
111
- or if you don't use the RoutingBundle, you can configure it with
123
+ The ContentListener
124
+ ~~~~~~~~~~~~~~~~~~~
125
+
126
+ The ``Symfony\Cmf\Bundle\SeoBundle\EventListener\ContentListener `` looks for a
127
+ content document in the request attributes. If it finds a document, it calls
128
+ ``SeoPresentationInterface::updateSeoPage ``.
129
+
130
+ If the :doc: `RoutingBundle <../routing/introduction >` is installed, the default
131
+ attribute name is defined by the constant ``DynamicRouter::CONTENT_KEY ``. When
132
+ not using the RoutingBundle, you need to configure a key in
112
133
``cmf_seo.content_key ``.
113
- This bundle provides two ways of using this metadata:
134
+
135
+ Extracting Metadata
136
+ ~~~~~~~~~~~~~~~~~~~
137
+
138
+ A service implementing ``SeoPresentationInterface `` is responsible for
139
+ determining metadata from an object and updating the Sonata ``SeoPage `` with that
140
+ information. A default implementation is provided as ``cmf_seo.presentation ``.
141
+
142
+ Defining Metadata
143
+ ~~~~~~~~~~~~~~~~~
144
+
145
+ This bundle provides two ways to define metadata on objects:
114
146
115
147
#. Implementing the ``SeoAwareInterface `` and persisting the ``SeoMetadata ``
116
148
with the object.
117
- #. Using the extractors , to extract the ``SeoMetadata `` from already existing
118
- values (e.g. the title of the page).
149
+ #. Using `` ExtractorInterface `` instances , to extract the ``SeoMetadata `` from
150
+ already existing values (e.g. the title of the page).
119
151
120
152
You can also combine both ways, even on the same document. In that case, the
121
153
persisted ``SeoMetadata `` can be changed by the extractors, to add or tweak
122
154
the current available SEO information. For instance, if you are writing a
123
155
``BlogPost `` class, you want the SEO keywords to be set to the tags/category
124
- of the post and any additional tags set by the admin .
156
+ of the post and any additional tags set by the editor .
125
157
126
- Persisting the ``SeoMetadata `` with the document makes it easy to edit for the
127
- admin , while using the extractors are perfect to easily use values from the
128
- displayed content.
158
+ Persisting the ``SeoMetadata `` with the document makes it easy to override SEO
159
+ information for the editor , while using the extractors adds the convenience
160
+ that values from the normal content of the document can be reused .
129
161
130
- Both ways are documented in detail in separate sections:
162
+ Both methods are documented in detail in separate sections:
131
163
132
164
* :doc: `seo_aware `
133
165
* :doc: `extractors `
0 commit comments