html - 如何覆盖 HWIOAuthBundle twig 文件

标签 html facebook symfony twig hwioauthbundle

我是 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/

相关文章:

javascript - PHP MySQL 使用 jQuery 使用包含换行符的文本填充 Textarea

javascript - 道场店概念

html - Bootstrap 响应式面板,里面有一个宽大的下拉菜单,打破了移动

javascript - Angular 4 - 从子组件发出的停止函数

python - Facebook Messenger 与 Flask

php - 用户测试中多个客户端的 Symfony 4.4 弃用警告已弃用,仍存在于文档中

xcode - 在 Facebook 上快速分享

java - 在java中使用spring-social-facebook执行简单的FQL查询

Symfony2 phpunit 功能测试自定义用户身份验证在重定向后失败( session 相关)

php - 通过 CompilerPass 注册自定义 AttributeBag