如何覆盖 HWIOAuthBundle 树枝文件

2022-01-22 00:00:00 symfony html facebook twig hwioauthbundle

我是 Symfony2.3 +FosUserBundle 的 HWIOAuthBundle 新手.我在我的项目中使用这个捆绑包登录 facebook、twitter、googleplus.

I am new in HWIOAuthBundle with Symfony2.3 +FosUserBundle. I am using this bundle for facebook, twitter, googleplus login in my project.

我已经成功安装了这个并且工作正常.但我想覆盖 login.html.twig 因为我想在我们的 twig 文件中显示 facebook、twitter、google 以及图像,但我不知道如何在 HWIOAuthBundle 中执行此操作.

I have successfully install this and this working fine. But I want to override login.html.twig because I want to show facebook , twitter, google plus Images to our twig file but I don't know How I can do this in HWIOAuthBundle.

我的 login.html.twig

My login.html.twig

{% block content %}
  {# Bonus: Show all available login link in HWIOAuthBundle #}
  {% render(controller('HWIOAuthBundle:Connect:connect')) %}
{% endblock %}

基础 HWIOAuthBundle login.html.twig

Base 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 页面中显示该类型的是哪一个:

Which one showing this type in Html page:

Facebook
Google Plus
Twitter

当点击任何一个然后重定向到他的页面(Facebook,Twitter,Google Plus)时默认显示.

this is show by default when click any one then redirect to his page(Facebook,Twitter,Google Plus).

但我想展示这种类型的 HTML:

But And I want to show this type 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 个新视图:

To be more specific about your case, you should create 2 new views:

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 使用其他几个视图(用于确认配置文件等).

Do not be tempted to put this login page in the first file, because OAUthBundle uses several other views (to confirm profile, etc).

这个例子取自 symfony-quickstart 项目.

This example is taken from symfony-quickstart project.

相关文章