自定义 FosUserTemplate
Customize FosUserTemplate
我试图覆盖 FOSUser 模板并向我的页面添加一些 html 项,但我收到此错误:
Unexpected token "end of template" of value "" ("end of statement block" expected).
这里是 base.html.twig 页面:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other
head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="favicon.ico">
{% block stylesheets %}{% endblock %}
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
{% stylesheets
"css/myStyle.css"
%}
<link rel="stylesheets" href="{{ asset_url }}">
<title>{% block title %}Hello!{% endblock %}</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- Latest compiled and minified JavaScript -->
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js">
</script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js">
</script>
<![endif]--> </head>
<body>
{% block topnav %}
{% include '::topnav.html.twig' %}
{% endblock %}
<div class="container">
{% block content %}{% endblock %} </div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
{% block javascripts %}{% endblock %}
这是 layout.html.twig 页面:
{% extends '::base.html.twig' %}
{% block content %}
<div>
{% if is_granted("IS_AUTHENTICATED_REMEMBERED") %}
{{ 'layout.logged_in_as'|trans({'%username%':
app.user.username}, 'FOSUserBundle') }} |
<a href="{{ path('fos_user_security_logout') }}">
{{ 'layout.logout'|trans({}, 'FOSUserBundle') }}
</a>
{% else %}
<a href="{{ path('fos_user_security_login') }}">{{
'layout.login'|trans({}, 'FOSUserBundle') }}</a>
{% endif %}
</div>
{% 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 %}
您的样式 sheet 必须声明如下
{% stylesheets
'path/to/style.css' %}
<link rel="stylesheet" href="{{ asset_url }}"/>
{% endstylesheets %}
您的 endstylesheets 丢失
去那里看看
https://symfony.com/doc/current/assetic/asset_management.html#including-css-stylesheets
参考官方文档:
如何覆盖模板:http://symfony.com/doc/master/bundles/FOSUserBundle/overriding_templates.html
如何覆盖 FormType :http://symfony.com/doc/master/bundles/FOSUserBundle/overriding_forms.html
我试图覆盖 FOSUser 模板并向我的页面添加一些 html 项,但我收到此错误:
Unexpected token "end of template" of value "" ("end of statement block" expected).
这里是 base.html.twig 页面:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> <meta name="description" content=""> <meta name="author" content=""> <link rel="icon" href="favicon.ico"> {% block stylesheets %}{% endblock %} <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> {% stylesheets "css/myStyle.css" %} <link rel="stylesheets" href="{{ asset_url }}"> <title>{% block title %}Hello!{% endblock %}</title> <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> <!-- Latest compiled and minified JavaScript --> <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> <!--[if lt IE 9]> <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"> </script> <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"> </script> <![endif]--> </head> <body> {% block topnav %} {% include '::topnav.html.twig' %} {% endblock %} <div class="container"> {% block content %}{% endblock %} </div> <!-- Bootstrap core JavaScript ================================================== --> <!-- Placed at the end of the document so the pages load faster --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
{% block javascripts %}{% endblock %}
这是 layout.html.twig 页面:
{% extends '::base.html.twig' %}
{% block content %}
<div> {% if is_granted("IS_AUTHENTICATED_REMEMBERED") %} {{ 'layout.logged_in_as'|trans({'%username%': app.user.username}, 'FOSUserBundle') }} | <a href="{{ path('fos_user_security_logout') }}"> {{ 'layout.logout'|trans({}, 'FOSUserBundle') }} </a> {% else %} <a href="{{ path('fos_user_security_login') }}">{{ 'layout.login'|trans({}, 'FOSUserBundle') }}</a> {% endif %} </div> {% 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 %}
您的样式 sheet 必须声明如下
{% stylesheets
'path/to/style.css' %}
<link rel="stylesheet" href="{{ asset_url }}"/>
{% endstylesheets %}
您的 endstylesheets 丢失
去那里看看 https://symfony.com/doc/current/assetic/asset_management.html#including-css-stylesheets
参考官方文档:
如何覆盖模板:http://symfony.com/doc/master/bundles/FOSUserBundle/overriding_templates.html
如何覆盖 FormType :http://symfony.com/doc/master/bundles/FOSUserBundle/overriding_forms.html