首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >覆盖FOSUserBUndle布局

覆盖FOSUserBUndle布局
EN

Stack Overflow用户
提问于 2019-04-01 00:29:10
回答 1查看 172关注 0票数 0

我在我的项目上安装和配置了FOSUserBundle (我正在使用symfony 4)。安装是没有问题的。我重写了FOSUserBundle模板,但与layout.html.twig和base.html.twig没有被覆盖的情况相同。

我的layout.html.twig:

代码语言:javascript
复制
{% extends 'base.html.twig' %}

{% block body %}
    <div class="container">
        <div class="row">
            <div class="col-xs-12">
                {% block fos_user_content %}{% endblock %}
            </div>
        </div>
    </div>
{% endblock %}

我的base.html.twig:

代码语言:javascript
复制
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>{% block title %}Welcome!{% endblock %}</title>
        {% block stylesheets %}{% endblock %}
    </head>
    <body>
        {% block body %}{% endblock %}
        {% block javascripts %}{% endblock %}
    </body>
</html>

唯一使用的FOSUserBundle。其次,symfony调试工具栏消失。

FOSUserBundle被覆盖在那里:模板/包/FOSUserBundle

在文件夹中,我添加了所有的FOSUserBundle子文件夹:安全注册配置文件.

模板结构

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-01 07:51:18

我就是这样做的:

base.html.twig

代码语言:javascript
复制
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <title>
        {% block title %}Admin panel{% endblock %}
    </title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="robots" content="noindex,nofollow"/>
    <link rel="stylesheet" href="{{ asset('css/bootstrap.min.css') }}"/>
</head>
<body>

<div class="container">
    {% block content %}{% endblock %}
</div>

<script src="{{ asset('js/jquery-3.3.1.min.js') }}"></script>
<script src="{{ asset('js/bootstrap.min.js') }}"></script>
</body>
</html>

layout.html.twig

代码语言:javascript
复制
{% extends 'bundles/FOSUserBundle/base.html.twig' %}

{% block content %}
    {% if app.request.hasPreviousSession %}
        {% for type, messages in app.session.flashbag.all() %}
            {% for message in messages %}
                <div class="flash-{{ type }}">
                    {{ message }}
                </div>
            {% endfor %}
        {% endfor %}
    {% endif %}

    <div>
        {% block fos_user_content %}
        {% endblock fos_user_content %}
    </div>
{% endblock %}

Security/login.html.twig

代码语言:javascript
复制
{% extends "bundles/FOSUserBundle/layout.html.twig" %}
{% trans_default_domain 'FOSUserBundle' %}

{% block title %}Sing in{% endblock %}

{% block fos_user_content %}
    <div class="jumbotron">
        <h4 class="text-center">Sign in</h4>
        {% if error %}
            <div class="alert alert-danger">{{ error.messageKey|trans(error.messageData, 'security') }}</div>
        {% endif %}

        <form method="post" action="{{ path("fos_user_security_check") }}">
            <input type="hidden" name="_csrf_token" value="{{ csrf_token }}"/>
            <div class="form-group">
                <label for="username">Email:</label>
                <input type="email" name="_username" class="form-control" id="username" value="{{ last_username }}"
                       autocomplete="off">
            </div>
            <div class="form-group">
                <label for="password">Password:</label>
                <input type="password" id="password" name="_password" class="form-control">
            </div>
            <div class="form-group form-check">
                <label class="form-check-label">
                    <input class="form-check-input" type="checkbox" id="remember_me" name="_remember_me" value="on">Remember
                    me
                </label>
            </div>
            <button name="_submit" type="submit" class="btn btn-primary">{{ 'security.login.submit'|trans }}</button>
        </form>
    </div>
{% endblock fos_user_content %}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55446701

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档