javascript - Style/scripts for included blocks -


ok, i'm not sure if i've missed trick here. can't find in docs or online solution. i'm trying include big block of javascript template block same goes styles. have template structure summarised:

{# base.html.twig %} <html>   <head>     <title>{% block title %}base template{% endblock %}</title>     {% block stylesheets %}       <link rel="stylesheet" href="{{ asset('bundles/thisbundle/css/theme.css') }}" type="text/css" media="all" />     {% endblock %}     {% block scripts %}{% endblock %}   <head>   <body>     {% block content %}hello base{% endblock %}     {% block javascripts %}     {% endblock %}   </body> </html>  {# index.html.twig #} {% extends 'base.html.twig %} {% block content %}   {% include 'thisbundlebundle::templatewithascript.html.twig' %}   <p>some content here<p>   {% include 'thisbundlebundle::anothertemplatewithascript.html.twig' %} {% endblock %} 

now here's problem. template add content of javascripts/stylesheets block include within content block , can't extend index.html.twig in templatewithascript.html.twig, want work:

{# templatewithascript.html.twig #} {% block stylesheets %}   <link href="{{ asset('bundles/thisbundle/css/blockspecificstyle.css') }}" rel="stylesheet" type="text/css" /> {% endblock %} {% block body %}   <p>click here , happens</p> {% endblock %} {% block javascripts %}   <script type="text/javascript">     $(document).ready(function(){       $("p").click(function(){         $(this).hide();       });     });   </script> {% endblock %} 

or limitation , have include style/scripts in template includes content? thanks. lu

ok answer own question! importing macros answer i've come with, ie:

{# index.html.twig #} {% extends 'base.html.twig' %} {% import 'thisbundlebundle::templatewithascript.html.twig' importedtemplate %} {% block content %}   {{ importedtemplate.content }} {% endblock %} {% block javascripts %}   {{ importedtemplate.js }} {% endblock %}  {# templatewithascript.html.twig #} {% macro content %}   <p>click here , happens</p> {% endmacro %} {% macro js %}   <script type="text/javascript">     $(document).ready(function(){       $("p").click(function(){         $(this).hide();       });     });   </script> {% endmacro %} 

it seems work not sure if im bending rules bit there. , seems there should easier way allows me work within templatewithascript.html.twig?


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -