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>
        <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 %}

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

      {% block javascriptsFooter %}

      {% endblock javascriptsFooter %}

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? *

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 duanreng3439 2017-04-11 14:38

    You have the wrong string in extends. Change

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


    {% 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.

    点赞 评论 复制链接分享