How create modal window with Twig template and Twitter-Bootstrap

久未见 提交于 2019-12-05 21:32:44

问题


I use Symfony and boostrap to customize the style of my website. I have a twig file : register_content.html.twig which contains a register form.

In my index.html.twig I want to have something like that :

<a href="{{ path('fos_user_registration_register') }}" class="btn" data-toggle="modal">Je m'inscris !</a>

To display the content of the register form in a modal window, but it doesn't work.

I try to use the twitter-bootstrap documentation here : http://bootstrap.braincrafted.com/javascript#modals

But I can't find a way to apply it easily for twig in symfony...

Could you help me ?

Thanks


回答1:


Your problem is totally unrelated to symfony or twig. You are missing data-attributes for the modal to work!

You can do it the following ways:

  1. Integrate the register form inside your index.html in a modal box and following the bootstrap example for a static modal box:

    <button type="button" data-toggle="modal" data-target="#myModal">I register !</button>
    
    <div id="myModal" class="modal hide fade">
        <!-- register form here -->
    </div>
    
  2. You could also load the content for the registration form through ajax. In this case, see the remote option for modals:

    <a data-toggle="modal" href="{{ path('fos_user_registration_register') }}" data-target="#myModal">click me</a>
    
    <div id="myModal"></div>
    

    Just make sure to not send any layout when an ajax request is performed against the url, because otherwise you'll have a complete html page inside your div, which is neither valid (html-page inside html-page) nor a good idea.



来源:https://stackoverflow.com/questions/15867580/how-create-modal-window-with-twig-template-and-twitter-bootstrap

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