Twig更改元数据

时间:2016-12-09 08:16:44

标签: twig

我需要在树枝上获取页面的元数据,用我的值替换它们,但我找不到如何获取它们。

现在我有:

{% if spec.name matches '{meta}'  %}
       {% set getdatas = app.request.server.get('REQUEST_URI') %} // use uri for test, i need the same but with meta_title, meta_description...
       {{ dump(uri|replace({'domaine': spec.name})) }}
{% endif %}

2 个答案:

答案 0 :(得分:2)

如果要覆盖Twig中的任何内容,则需要为其创建一个块。举个例子:

base.html.twig

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  {% block meta %}{% endblock %}
  <title>{% block title %}{% endblock %}</title>
  {% block stylesheets %}{% endblock %}
</head>
<body>
  {% block body %}{% endblock %}
</body>
</html>

parent.html.twig

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

{% block stylesheets %}
  # My extra styles...
{% endblock %}

{% block body %}
  <div>
    {% block content %}{% endblock %}
  </div>
{% endblock %}

child.html.twig

{% extends 'parent.html.twig' %}

{% block title %}My page{% endblock %}

{% block meta %}
  <meta key="value">
{% endblock %}

{% block content %}My content{% endblock %}

答案 1 :(得分:0)

我的父模板:

{% extends 'DesignBundle::Front/layout.html.twig' %}

{% block stylesheets %}
{{ parent() }}



<link rel="stylesheet" href="{{ asset('bundles/extension/css/flag-icon.min.css') }}">
<link rel="stylesheet" href="{{ asset('bundles/extension/css/main.css') }}">
{% endblock %}


{% block title %}
{{ _("Caractéristiques des noms de domaine") ~ " ." ~ extension.nomExt|idna_decode }}</code>



{% if extension.countryName is not empty %}
   {{ " - " ~ extension.countryName|utf8_fix }}
   {% endif %}
{% endblock %}


{% block content %} // view in first post is call here
{% include 'ExtensionBundle:New_fiche:show_content.html.twig' %}
{% endblock %}
相关问题