douyan1903 2017-04-11 14:02
浏览 24
已采纳

Symfony FosUserBundle从我的默认模板扩展到另一个包

On my symfony 3.2 project I am using the FOSUserBundle for User Registration and authentication. What I am trying to do is to apply a custom theme to the registration form.

Therefore I have made the app/Resources/views/base.html.twig that is my application's base template:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>{% block title %}Welcome!{% endblock %}</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        {% block stylesheets %}
          <link rel="stylesheet" type="text/css" href="{{asset('assets/vendor/bootstrap/css/bootstrap.css')}}" ></link>
          <link rel="stylesheet" type="text/css" href="{{asset('assets/vendor/adminlte/adminlte.css')}}" ></link>
          <link rel="stylesheet" type="text/css" href="{{asset('assets/vendor/adminlte/skin-blue.css')}}" ></link>
        {% endblock %}
        <link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />

        {% block javascriptsHeader %}

        {% endblock %}

    </head>
    <body class="{{ classes }}">
      {% block body %}
      {% endblock body %}

      {% block javascriptsFooter %}

      {% endblock javascriptsFooter %}
   </body>
</html>

I have also changed Resources/FOSUSerBundle/views/layout.html.twig with the following content:

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

{% body %}
  {% block fos_user_content %}
  {% endblock fos_user_content %}
{% endblock body %}

As seen on: * Symfony2: How to extend a Bundle? * http://symfony.com/doc/current/bundles/FOSUserBundle/overriding_templates.html

But I get the following error:

Unexpected token "punctuation" of value ":" ("end of statement block" expected).

Do you have any idea how to use my default template as registration from template?

  • 写回答

1条回答 默认 最新

  • duanreng3439 2017-04-11 14:38
    关注

    You have the wrong string in extends. Change

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

    to

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

    and it should work.

    NOTE: Using ::base.html means that the template engine will look for base.html in app/Resources/views/base.html.twig. Setting AppBundle::base.html.twig is wrong. If the template was located in a bundle (i.e. AppBundle - src/AppBundle), then the path would look something like @AppBundle/base.html.twig.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模数学建模需要
  • ¥15 已知许多点位,想通过高斯分布来随机选择固定数量的点位怎么改
  • ¥20 nao机器人语音识别问题
  • ¥15 怎么生成确定数目的泊松点过程
  • ¥15 layui数据表格多次重载的数据覆盖问题
  • ¥15 python点云生成mesh精度不够怎么办
  • ¥15 QT C++ 鼠标键盘通信
  • ¥15 改进Yolov8时添加的注意力模块在task.py里检测不到
  • ¥50 高维数据处理方法求指导
  • ¥100 数字取证课程 关于FAT文件系统的操作