php - Append inline scripts inside Twig layout block -


i have layout looks this:

<html> <body>    <!-- omitted -->    <div class="content">     {% block body %}{% endblock %}   </div>    <script src="js/vendor.js"></script>   {% block javascripts %}     <!-- want able inject inline scripts sub-templates here -->   {% endblock %}  </body>  </html> 

then have register_content.html.twig template overridden fosuserbundle , in trying inject script "javascripts" block so:

{% block javascripts %}   <script>     // inline js   </script> {% endblock %} 

the problem having inline script seems injected @ end of "body" block , not in "scripts" block.

this output getting:

      <!-- should below js/vendor.js scripts -->             <script>         // inline js       </script>     </div> </div>  <script src="js/vendor.js"></script> 

what doing wrong? problem lie fosuserbundle , it's own templates inherits (it still uses layout , have in it; not it's own layout). i'm confused here.

p.s. i'm total newbie symfony/twig please easy on me.

edit: these fosuserbundle layout , templates have overriden:

app/resources/fosuserbundle/views/layout.html.twig:

{% extends 'acmewebbundle::layout.html.twig' %}  {% block title %}acme demo application{% endblock %}  {% block body %}     {% block fos_user_content %}{% endblock %} {% endblock %}  {% block javascripts %}     {{ parent() }} {% endblock %} 

app/resources/fosuserbundle/views/registration/register.html.twig:

{% extends "fosuserbundle::layout.html.twig" %}  {% block body %}     {% block fos_user_content %}         {% include "fosuserbundle:registration:register_content.html.twig" %}             {% endblock fos_user_content %} {% endblock %}  {% block javascripts %}     {% parent() %} {% endblock %} 

app/resources/fosuserbundle/views/registration/register_content.html.twig:

<div class="page-header">     <h2>register</h2> </div>  <form action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} method="post" class="fos_user_registration_register form-horizontal">     <!-- html omitted -->  </form>  {% block javascripts %}     {% javascripts '@acmewebbundle/resources/public/js/app.js' %}     <script>         // jquery undefined because gets defined below 'javascripts' block in parent layout         console.dir(window.jquery);     </script>     {% endjavascripts %} {% endblock %} 

after edit situation more clear.

the behaviour expect works template inheritance only; won't work include, way have in app/resources/fosuserbundle/views/registration/register.html.twig.

to want, 1 of following:

  • place inline javascript code javascript block of app/resources/fosuserbundle/views/registration/register_content.html.twig inside javascript block of app/resources/fosuserbundle/views/registration/register.html.twig

  • let template app/resources/fosuserbundle/views/registration/register.html.twig inherit app/resources/fosuserbundle/views/registration/register_content.html.twig , override blocks needed (register_content.html.twig not extend layout.html.twig, not make sense)


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -