@@ -72,8 +72,8 @@ The only thing to do now is to use the twig helper in your templates:
72
72
<html>
73
73
<head>
74
74
{{ sonata_seo_title() }}
75
+
75
76
{{ sonata_seo_metadatas() }}
76
- {{ sonata_seo_link_canonical() }} // needed later
77
77
</head>
78
78
<body>
79
79
<p>Some page body.</p>
@@ -125,9 +125,9 @@ Both ways are documented in detail in seperate sections:
125
125
Choosing the Original Route Pattern
126
126
-----------------------------------
127
127
128
- Search engines punish you, when you provide the same content under several
129
- URLs. The CMF allows you to have several URLs for the same content if you
130
- need that. There are two solutions to avoid penalties with search engines:
128
+ Search engines don't like it when you provide the same content under several
129
+ URLs. The CMF allows you to have several URLs for the same content if you need
130
+ that. There are two solutions to avoid penalties with search engines:
131
131
132
132
* Create a canonical link that identifies the original URL:
133
133
``<link rel="canonical" href="/route/org/content"> ``;
@@ -162,23 +162,13 @@ you want to change that to redirect instead, you can set the
162
162
),
163
163
);
164
164
165
- .. todo
166
-
167
- Configuring the Default Values
168
- ------------------------------
165
+ Defining a Default
166
+ ------------------
169
167
170
- You know now how to work with objects configuring SEO data. However, in some
171
- cases the object doesn't provide any information. Then you have to configure a
172
- default. You can configure the defaults for the SonataSeoBundle, these
173
- defaults will be overriden by the metadata from the CmfSeoBundle. However, you
174
- might want to combine.
175
-
176
- Visiting the site with the url ``/seo-content `` (same template shown above)
177
- will show a Page with "Documents own tile" as title, "This ist the text for
178
- the description meta tag" in the description, "Seo, Content" in the keywords
179
- and a canonical link with ``href="/original/url/of/content" ``. But what about
180
- some default string to just concatenate defaults and documents own values?
181
- Just add some more configs to the cmf_seo configuration section.
168
+ You've learned everything about extracting SEO information from objects.
169
+ However, in some cases the object doesn't provide any information or there is
170
+ no object (e.g. on a login page). For these cases, you have to configure a
171
+ default value. These default values can be configured for the SonataSeoBundle:
182
172
183
173
.. configuration-block ::
184
174
@@ -187,170 +177,178 @@ Just add some more configs to the cmf_seo configuration section.
187
177
# app/config/config.yml
188
178
sonata_seo :
189
179
page :
180
+ title : A Default Title
190
181
metas :
191
182
names :
192
183
keywords : default, sonata, seo
193
- cmf_seo :
194
- title : default_title_key
195
- description : default_title_key
196
-
197
- .. code-block :: xml
198
-
199
- <!-- app/config/config.xml -->
200
- <container xmlns =" http://symfony.com/schema/dic/services" >
201
- <config
202
- xmlns =" http://cmf.symfony.com/schema/dic/seo"
203
- title =" default_title_key"
204
- description =" default_title_key" >
205
- </config >
206
- </container >
184
+ description : A default description
207
185
208
186
.. code-block :: php
209
187
210
188
// app/config/config.php
211
189
$container->loadFromExtension(
212
190
'sonata_seo', array(
213
191
'page' => array(
192
+ 'title' => 'A Default Title',
214
193
'metas' => array(
215
194
'names' => array(
216
- 'keywords' => 'default, key, other',
195
+ 'keywords' => 'default, key, other',
196
+ 'description' => 'A default description',
217
197
),
218
198
),
219
199
),
220
200
),
221
- 'cmf_seo' => array(
222
- 'title' => 'default_title_key',
223
- 'description' => 'default_description_key',
224
- ),
225
201
);
226
202
227
- As you will notice, you got the opportunity to set Symfony translation key for
228
- your default values for title and description. So you will got
229
- Multi-Language-Support out of the box. Just define your values for default
230
- title/description as translations:
231
-
232
- .. code-block :: xml
233
-
234
- <!-- app/Resources/translations/messages.en.xliff -->
235
- <?xml version =" 1.0" encoding =" utf-8" ?>
236
- <xliff xmlns =" urn:oasis:names:tc:xliff:document:1.2" version =" 1.2" >
237
- <file source-language =" en" target-language =" en" datatype =" plaintext" original =" messages.en.xliff" >
238
- <body >
239
- <trans-unit id =" default_title_key" >
240
- <source >default_title_key</source >
241
- <target >%content_title% | Default title</target >
242
- </trans-unit >
243
- <trans-unit id =" default_description_key" >
244
- <source >default_description_key</source >
245
- <target >Default description. %content_description%</target >
246
- </trans-unit >
247
- </body >
248
- </file >
249
- </xliff >
250
-
251
- If you want to concatenate your documents values with the default ones you
252
- need them as parameters in you translation target.
253
-
254
- .. tip ::
255
-
256
- If you does not what to open a translation file for two entry, just set
257
- ``Default title | %%content_title%%``or ``Default description.
258
- %%content_description%% ``.
259
-
260
- For changing the default translation domain (messages), the SeoBundle provides
261
- a configuration value:
203
+ The Standard Title and Description
204
+ ----------------------------------
205
+
206
+ Most of the times, the title of a site has a static and a dynamic part. For
207
+ instance, "The title of the Page - Symfony". Here "- Symfony" is static and
208
+ "The title of the Page" will be replaced by the current title. It is of course
209
+ not nice if you need to add this static part to all your titles in documents.
210
+
211
+ That's why the CmfSeoBundle provides standard titles and descriptions. When
212
+ using these settings, there are 2 placeholders available: ``%content_title% ``
213
+ and ``%content_description% ``. This will be replaced with the title extracted
214
+ from the content object and the description extracted from the content object.
215
+
216
+ For instance, to configure the titles of the symfony.com pages, you would do:
262
217
263
218
.. configuration-block ::
264
219
265
220
.. code-block :: yaml
266
221
267
222
# app/config/config.yml
268
223
cmf_seo :
269
- translation_domain : AcmeDemoBundle
224
+ title : " %%content_title%% - Symfony "
270
225
271
226
.. code-block :: xml
272
227
273
228
<!-- app/config/config.xml -->
274
- <container xmlns =" http://symfony.com/schema/dic/services" >
275
- <config
276
- xmlns =" http://cmf.symfony.com/schema/dic/seo"
277
- translation-domain =" AcmeDemoBundle" >
278
- </config >
279
- </container >
229
+ <config xmlns =" http://cmf.symfony.com/schema/dic/seo"
230
+ title =" %%content_title%% - Symfony"
231
+ />
280
232
281
233
.. code-block :: php
282
234
283
235
// app/config/config.php
284
- $container->loadFromExtension(
285
- 'cmf_seo' => array(
286
- 'translation_domain' => 'AcmeDemoBundle',
287
- ),
288
- );
236
+ $container->loadFromExtension('cmf_seo', array(
237
+ 'title' => '%%content_title%% - Symfony',
238
+ ));
289
239
290
- Preface
291
- -------
240
+ .. caution ::
292
241
293
- Search engines punish you when you provide the same content under several
294
- URLs. The CMF allows you to have several URLs for the same content if you
295
- need that. There are two solutions to avoid penalties with search engines:
242
+ Be sure to escape the percentage characters by using a double percentage
243
+ character, otherwise the container will try to replace it with the value
244
+ of a container parameter.
296
245
297
- * Create a canonical link that identifies the original URL:
298
- ``<link rel="canonical" href="/route/org/content"> ``;
299
- * Redirect to THE original url.
246
+ This syntax might look familiair if you have used with the Translation
247
+ component before. And that's correct, under the hood the Translation component
248
+ is used to replace the placeholders with the correct values. This also means
249
+ you get Multi Language Support for free!
250
+
251
+ For instance, you can do:
252
+
253
+ .. configuration-block ::
254
+
255
+ .. code-block :: yaml
300
256
301
- Both take care on search engines, which does not like it to have same content
302
- under different routes.
257
+ # app/config/config.yml
258
+ cmf_seo :
259
+ title : seo.title
260
+ description : seo.description
261
+
262
+ .. code-block :: xml
263
+
264
+ <!-- app/config/config.xml -->
265
+ <config xmlns =" http://cmf.symfony.com/schema/dic/seo"
266
+ title =" seo.title"
267
+ description =" seo.description"
268
+ />
269
+
270
+ .. code-block :: php
271
+
272
+ // app/config/config.php
273
+ $container->loadFromExtension('cmf_seo', array(
274
+ 'title' => 'seo.title',
275
+ 'description' => 'seo.description',
276
+ ));
277
+
278
+ And then configure the translation messages:
279
+
280
+ .. configuration-block ::
303
281
304
- The SeoBundle uses sonatas SeoBundle and its TwigHelper to render the the
305
- `SeoMetadata ` into your Pag. So you should have a look at the documentation at
306
- `sonata seo documentation_ `
282
+ .. code-block :: xml
283
+
284
+ <!-- app/Resources/translations/messages.en.xliff -->
285
+ <?xml version =" 1.0" encoding =" utf-8" ?>
286
+ <xliff xmlns =" urn:oasis:names:tc:xliff:document:1.2" version =" 1.2" >
287
+ <file source-language =" en" target-language =" en" datatype =" plaintext" original =" file.ext" >
288
+ <body >
289
+ <trans-unit id =" seo.title" >
290
+ <source >seo.title</source >
291
+ <target >%content_title% | Default title</target >
292
+ </trans-unit >
293
+ <trans-unit id =" seo.description" >
294
+ <source >seo.description</source >
295
+ <target >Default description. %content_description%</target >
296
+ </trans-unit >
297
+ </body >
298
+ </file >
299
+ </xliff >
300
+
301
+ .. code-block :: php
302
+
303
+ // app/Resources/translations/messages.en.php
304
+ return array(
305
+ 'seo' => array(
306
+ 'title' => '%content_title% | Default title',
307
+ 'description' => 'Default description. %content_description',
308
+ ),
309
+ );
310
+
311
+ .. code-block :: yaml
312
+
313
+ # app/Resources/translations/messages.en.yml
314
+ seo :
315
+ title : " %content_title% | Default title"
316
+ description : " Default description. %content_description%"
307
317
308
- For redirects instead of canonical links (default) set the following option:
318
+ For changing the default translation domain (messages), you should use the
319
+ ``cmf_seo.translation_domain `` setting:
309
320
310
321
.. configuration-block ::
311
322
312
323
.. code-block :: yaml
313
324
314
325
# app/config/config.yml
315
326
cmf_seo :
316
- original_route_pattern : redirect
327
+ translation_domain : AcmeDemoBundle
317
328
318
329
.. code-block :: xml
319
330
320
331
<!-- app/config/config.xml -->
321
332
<container xmlns =" http://symfony.com/schema/dic/services" >
322
- <config
323
- xmlns =" http://cmf.symfony.com/schema/dic/seo"
324
- original-route-pattern =" redirect" >
325
- </config >
333
+ <config xmlns =" http://cmf.symfony.com/schema/dic/seo"
334
+ translation-domain =" AcmeDemoBundle"
335
+ />
326
336
</container >
327
337
328
338
.. code-block :: php
329
339
330
340
// app/config/config.php
331
341
$container->loadFromExtension(
332
342
'cmf_seo' => array(
333
- 'original_route_pattern' => 'redirect ',
343
+ 'translation_domain' => 'AcmeDemoBundle ',
334
344
),
335
345
);
336
346
337
- This value will cause a redirect to the url persisted in the ``originalUrl ``
338
- property of the ``SeoMetadata ``.
339
-
340
- The SeoMetadata contains a form type for your Symfony Form. Just create you
341
- form with the following key:
342
-
343
- .. code-block :: php
344
-
345
- $formBuilder
346
- ...
347
- ->add('seoMetadata', 'seo_metadata', array('label' => false));
348
- ...
349
- ;
350
-
351
- For SonataAdminBundle user the SeoBundle provides an admin extension to add
352
- that form to your form configuration.
347
+ Conclusion
348
+ ----------
353
349
350
+ That's it! You have now created a SEO optimized website using nothing more
351
+ than a couple of simple settings.
354
352
355
353
.. _`SonataSeoBundle` : https://github.com/sonata-project/SonataSeoBundle
356
354
.. _`with composer` : http://getcomposer.org
0 commit comments