Skip to content

Latest commit

 

History

History
102 lines (63 loc) · 4.09 KB

README.md

File metadata and controls

102 lines (63 loc) · 4.09 KB

MetaTagsBundle

Symfony Bundle to manage html meta tags by matching urls.

How it works

Based on the configuration provided by the user and/or a user custom service, MetaTagsBundle loads some urls and manages the association between an url and its meta tags values storing the data in the database.

To choose which urls must be managed by MetaTagsBundle, the routes generating them must be specified. There are some different methods to achieve this:

  • load all the routes of a bundle by including the bundle name in config.yml
  • for each route, specify an option in the Route annotation

For routes requiring parameters that must be fetched from database, there's the possibility to load entities from database, and associate the route parameters to the entities values in order to create urls.

For more specific needs, it is also possible to create a custom service which simply returns an array of urls.

Once the urls are loaded in MetaTagsBundle, you will be able to associate the following meta tags to each url:

  • title
  • description
  • keywords
  • author
  • language
  • robots
  • googlebot
  • og:title
  • og:description
  • og:image

Obviously it is possible to specify default values for each meta tag, used when a url has no or partially meta tags specified by the user.

Note: This bundle is in beta state at the moment, in test phase and almost ready for the first release.


Install

Installation instructions can be found in Installation.

The current version of this bundle is compatible with Symfony >= 2.2.*

Tag notes

We will try to provide tags as best as we can, to be used proficiently with composer or deps.

The development of this bundle is intended for Symfony versions >= 2.0.*; here is a brief explanation of the tagging system we use:

  • tags with the "X.Y" format are compatible with Symfony >= 2.2.*
  • tags with the "S2.0/X.Y" format are compatible with Symfony 2.0.*
  • tags with the "S2.1/X.Y" format are compatible with Symfony 2.1.*

If you are using symfony 2.0.*, follow this guide on the symfony-2.0.x branch.

If you are using symfony 2.1.*, follow this guide on the symfony-2.1.x branch.

More details about tagging and branching system used in CopiaincollaMetaTagsBundle can be found in Tagging and Branching system explanation.

Configure

To configure this bundle, read Configuration for all possible values.

Load urls

To generate urls starting by all routes contained in a bundle, just add the bundle name to config.yml, as explained here.

You can also add a single route by specifying an option in the Route annotation, like this:

@Route("/product/{id}/{slug}", name="product_show", options={"ci_metatags_expose"=true})

Through this option, you can also choose not to generate urls from a specific route:

@Route("/product/{id}/{slug}", name="product_show", options={"ci_metatags_expose"=false})

You can also generate urls for associating meta tags by fetching data from database; read the section Configuration#dynamic_routes.

Finally, you can also create your custom urls loader service, by following this guide.

Usage in the templates

Currently only twig is supported.

In the template containing an <head> tag, simply add:

<body>
    <head>
        {% render controller('CopiaincollaMetaTagsBundle:MetaTags:render') %}
        [...]
    </head>

    [...]
</body>

For a better explanation of usage in templates and advanced use, read Template usage.