Nll
Nll

Reputation: 872

How to use Meta Tags with Symfony 2.0

I don't know how to add Meta Tags in all the pages of my website?

Upvotes: 3

Views: 6832

Answers (3)

Nll
Nll

Reputation: 872

@F481,so I find a good solution,personnaly I do like that :

{% block meta %}
{% if (page.description) %}
    <meta name="description" content="{{ page.description }}">
{% endif %}

{% if (page.keywords) %}
    <meta name="keywords" content="{{ page.keywords }}">
{% endif %}
{% endblock %}

And I store my keywords and description for each page in DB.

Upvotes: 7

F481
F481

Reputation: 990

Correct, you can put your meta tags in the base layout of your site. For more complex wishes you can put them into a block and if you want you can overwrite them in your specific templates.

For more information take a look at the Symfony2 documentation Creating and using Templates.

Example:

in your base template, e.g. base.html.twig in app/Resources/view

{% block meta_title %}Default meta title{% endblock %}

in your template:

{% extends '::base.html.twig' %}

{% block meta_title %}{{ page.title }}{% endblock %}

Upvotes: 9

greg0ire
greg0ire

Reputation: 23255

Just put these meta tags in the base template of your site.

Upvotes: 0

Related Questions