我是 Symfony2.3 +FosUserBundle 的 HWIOAuthBundle 新手。 我在我的项目中将这个包用于 facebook、twitter、googleplus 登录。
我已经成功安装了这个并且工作正常。 但我想覆盖 login.html.twig,因为我想在我们的 twig 文件中显示 facebook、twitter、google 和图像,但我不知道如何在 HWIOAuthBundle 中执行此操作。
我的 login.html.twig
{% block content %}
{# Bonus: Show all available login link in HWIOAuthBundle #}
{% render(controller('HWIOAuthBundle:Connect:connect')) %}
{% endblock %}
基础 HWIOAuthBundle login.html.twig
{% extends 'HWIOAuthBundle::layout.html.twig' %}
{% block hwi_oauth_content %}
{% if error %}
<span>{{ error }}</span>
{% endif %}
{% for owner in hwi_oauth_resource_owners() %}
<a href="{{ hwi_oauth_login_url(owner) }}">{{ owner | trans({}, 'HWIOAuthBundle') }}</a> <br />
{% endfor %}
{% endblock hwi_oauth_content %}
在Html页面中显示该类型的是:
Facebook
Google Plus
Twitter
当点击任何一个然后重定向到他的页面(Facebook、Twitter、Google Plus)时,这是默认显示的。
但是我想显示这种类型的 HTML:
<!-- socials -->
<ul class="top-socials">
<li><a class="facebook" href="#">Facebook</a></li>
<li><a class="twitter" href="#">Twitter</a></li>
<li><a class="google-plus" href="#">Google+</a></li>
</ul>
我该怎么做?
最佳答案
为了更具体地说明您的情况,您应该创建 2 个新 View :
app/Resources/HWIOAuthBundle/views/layout.html.twig:
{# extends your own base template #}
{% extends 'MyBundle::layout.html.twig' %}
{% block title %}{{ 'Login' | trans }}{% endblock %}
{% block body %}
{% block hwi_oauth_content %}
{% endblock hwi_oauth_content %}
{% endblock %}
app/Resources/HWIOAuthBundle/views/Connect/login.html.twig:
{% extends 'HWIOAuthBundle::layout.html.twig' %}
{% block hwi_oauth_content %}
{# Display oauth errors (here using Bootstrap) #}
{% if error is defined and error %}
<div class="row">
<div class="col-md-12 alert alert-danger text-center">
<span class="error">{{ error }}</span>
</div>
</div>
{% endif %}
{# HWIOAuthBundle integration #}
<ul class="top-social">
<li><a class="#" href="{{ hwi_oauth_login_url('facebook') }}">Facebook</a></li>
<li><a class="#" href="{{ hwi_oauth_login_url('twitter') }}">Twitter</a></li>
<li><a class="#" href="{{ hwi_oauth_login_url('google') }}">Google+</a></li>
</ul>
{% endblock hwi_oauth_content %}
不要试图将此登录页面放在第一个文件中,因为 OAUthBundle 使用其他几个 View (以确认配置文件等)。
这个例子取自symfony-quickstart项目。
关于html - 如何覆盖 HWIOAuthBundle twig 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20998778/