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

Add SeoBundle twig extension documentation #705

Merged
merged 1 commit into from
Oct 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bundles/map.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ library or they introduce a complete new concept.
* :doc:`seo/seo_aware`
* :doc:`seo/extractors`
* :doc:`seo/configuration`
* :doc:`seo/twig`

* :doc:`tree_browser/index`

Expand Down
1 change: 1 addition & 0 deletions bundles/seo/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ SeoBundle
extractors
sitemap
configuration
twig
10 changes: 10 additions & 0 deletions bundles/seo/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ key in ``cmf_seo.content_key``.
You may also want to disable this listener when implementing your own mechanism
to extract SEO information.

The Twig Extension
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbu I added this here per your comment on mentioning the twig extension

~~~~~~~~~~~~~~~~~~

.. versionadded:: 1.2
The twig extension was added in SeoBundle 1.2.

This bundle provides a twig function ``cmf_seo_update_metadata``
which lets you populate the seo page from an object.
For details on using the twig extension, read :doc:`twig`.

Extracting Metadata
~~~~~~~~~~~~~~~~~~~

Expand Down
40 changes: 40 additions & 0 deletions bundles/seo/twig.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Setting Seo Metadata from Twig
==============================

.. versionadded:: 1.2
The twig extension was added in SeoBundle 1.2.

This bundle provides a twig function ``cmf_seo_update_metadata``
which lets you populate the seo page from an object.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbu I reworded this per your comment.

For details on how populating the SEO page works, read :doc:`introduction`.

You must call this function in your twig template before the calls to
``sonata_seo_title`` and ``sonata_seo_metadatas`` functions. The
recommended set up for this is to create a metadata block in your
base twig template and override it in a sub template, calling
``cmf_seo_update_metadata`` before calling ``parent()``.

.. code-block:: html+jinja

<!-- app/Resources/views/base.html.twig -->
<!DOCTYPE html>
<html>
<head>
{% block metadata %}
{{ sonata_seo_title() }}

{{ sonata_seo_metadatas() }}
{% endblock metadata %}
</head>
<body>
<p>Some page body.</p>
</body>
</html>

<!-- app/Resources/views/Blog/post.html.twig -->
{% extends 'base.html.twig' %}

{% block metadata %}
{{ cmf_seo_update_metadata(post) }}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbu Removed the do, you caught me trying to be clever.

{{ parent() }}
{% endblock metadata %}