Search code examples
phpsymfonytwigmetadatameta-tags

How to add meta tag in symfony3?


I want to add meta tags to my Symfony application.

How to use Meta Tags with Symfony 2.0
Twig change meta data
https://symfony.com/doc/current/cmf/bundles/seo/twig.html.
These links can't help me find out the correct answer.

This is my code. My page where I need to add the tag. Say "about.html.twig"

{% extends 'AppBundle::layout.html.twig' %}

{% block body %} 
.
.
.
{% endblock %} 

I wanted to know which one to use.

{% block meta %}{% endblock %} 

(or)

{% block metadata %}{% endblock %}

(or)

{% block head %}
    <head>
        <meta charset="UTF-8" />
{% endblock %}

Solution

  • meta or metadata or head are only the names. (not a statement) You can choose any name for this.

    for example

    base.html.twig

    <!doctype html>
    <html lang="en">
    {% extends 'AppBundle::layout.html.twig' %}
      {% block title %}Title Website{% endblock %}
        <meta charset="UTF-8" />//////Repeat on all pages
        <meta http-equiv="content-language" content="fa,en">//////Repeat on all pages
      {% block metaTag %}
          <meta name="{{ description }}" content="Your description">
      {% endblock %}
    
    {% block body %}
    
    {% endblock %}