我如何重写HWIOAuthBundle twig文件 [英] How can I Override HWIOAuthBundle twig file

查看:122
本文介绍了我如何重写HWIOAuthBundle twig文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是使用Symfony2.3 + FosUserBundle在HWIOAuthBundle中创建的。
我在facebook,twitter,googleplus登陆我的项目中使用这个包。



我已经成功安装了这个,并且这个工作正常。
但我想重写login.html.twig,因为我想将facebook,twitter,google plus Images添加到我们的twig文件中,但我不知道如何在HWIOAuthBundle中执行此操作。



我的login.html.twig

  {%block content%} 
{ #Bonus:显示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%}
{%在hwi_oauth_resource_owners所有者()%}
将A HREF = {{hwi_oauth_login_url(所有者)}} > {{所有者| trans({},'HWIOAuthBundle')}}< / a> < br />
{%endfor%}
{%endblock hwi_oauth_content%}

在Html页面中显示此类型:

  Facebook 
Google Plus
Twitter

这是默认情况下显示时点击任何一个,然后重定向到他的网页(Facebook,Twitter,Google Plus)。



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

 < ;! - 社交 - > 
< ul class =top-socials>
< li>< a class =facebookhref =#> Facebook< / a>< / li>
< li>< a class =twitterhref =#> Twitter< / a>< / li>
< li>< a class =google-plushref =#> Google +< / a>< / li>
< / ul>

我该怎么做?

解决方案

要更具体地了解您的案例,您应该创建2个新的视图:

app / Resources / HWIOAuthBundle / views /layout.html.twig

  {#扩展您自己的基本模板#} 
{%扩展'MyBundle :: layout.html.twig'%}

{%block title%} {{'Login'| (%endblock%)

{%block body%}
{%block hwi_oauth_content%}
{%endblock hwi_oauth_content%}
{%endblock% }

app / Resources / HWIOAuthBundle / views / Connect / login.html.twig kbd>:

  {%extend'HWIOAuthBundle :: layout.html.twig'%} 

{%block hwi_oauth_content%}

{#显示oauth错误(这里使用Bootstrap)#}
{%如果错误被定义并且错误%}

< div class =col-md-12 alert alert-danger text-center>
< span class =error> {{error}}< / span>
< / div>
< / div>
{%endif%}

{#HWIOAuthBundle整合#}

< 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 项目。


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

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.

My login.html.twig

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

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 %}

Which one showing this type in Html page:

Facebook
Google Plus
Twitter

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

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>

How can I do this ?

解决方案

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 %}

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

This example is taken from symfony-quickstart project.

这篇关于我如何重写HWIOAuthBundle twig文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆