如何覆盖HWIOAuthBundle twig文件

时间:2014-01-08 14:45:26

标签: html facebook symfony twig hwioauthbundle

我是使用Symfony2.3 + FosUserBundle在HWIOAuthBundle中的新手。 我在我的项目中使用此捆绑包进行facebook,twitter,googleplus登录。

我已经成功安装了这个并且工作正常。 但我想覆盖login.html.twig,因为我想在我们的twig文件中显示facebook,twitter,google plus Images但我不知道如何在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 个答案:

答案 0 :(得分:4)

为了更具体地说明您的情况,您应该创建2个新视图:

应用程序/资源/ HWIOAuthBundle /视图/ 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 %}

应用程序/资源/ HWIOAuthBundle /视图/连接/ 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使用其他几个视图(以确认配置文件等)。

此示例取自symfony-quickstart项目。

答案 1 :(得分:3)

你有两个解决方案:

  1. 使用捆绑继承并使用父路径优化模板
  2. 在你的app / Ressources /中声明一个模板:app / Ressources / AcmeBundle / Directory / template.html.twig(其中/AcmeBundle/Directory/template.html.twig与供应商中模板的路径完全相同)
  3. Doc:

相关问题