How can I Override HWIOAuthBundle twig file

梦想与她 提交于 2019-12-01 06:25:00

问题


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 ?


回答1:


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.




回答2:


You have two solutions for that :

  1. Use bundle inheritance and refine the template with parent path
  2. Declare a template in you app/Ressources/ like that : app/Ressources/AcmeBundle/Directory/template.html.twig (where /AcmeBundle/Directory/template.html.twig is the exact same path to the template in your vendor)

Doc :

  • http://symfony.com/doc/current/cookbook/bundles/inheritance.html
  • http://symfony.com/doc/2.0/book/templating.html#overriding-bundle-templates


来源:https://stackoverflow.com/questions/20998778/how-can-i-override-hwioauthbundle-twig-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!