Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • Ran into another problem Using a pure symfony response it seems doesn't allow you to attach assets - JS or CSS files to the render array. Doing so: $build['#attached']['library'] = 'mymodule/my-lib'; with the render array should output an html head tag and js/css files with the page but the attached library gets neglected for some reason. Then what is inside the twig template only gets printed out, even <html> is not present. Tried many things but none worked. My fear is that I might need to use {% block javascripts %} in the twig template, how to reference my js files then? Any idea? Commented Apr 30, 2016 at 15:28
  • By using a pure symfony response there is no html template. From your comment it seems, that you want to keep the html template and only override the page template. Did you try the code in the second question, I mean the question itself, because the OP has updated the code in the question with what was discussed in the comments. Commented Apr 30, 2016 at 16:24
  • Thanks for your reply 4k4, but I don't understand what is the difference between the html template and page template. Are you referring to the website general theme vs the module twig template? In your previous answer what do you mean by: Override page.html.twig and html.html.twig, remove anything out of this templates and put only that in what you want. Where are both files? Commented Apr 30, 2016 at 18:07
  • What is really daunting is when using pure symfony response you could still use the twig template of your module and outputting stuff such as {{ name }} still works but when using {{ attach_library() }} function directly from twig, it gets totally bypassed... Commented Apr 30, 2016 at 18:14
  • ... bypassing the theme is why you would use a symfony response. And without a theme you don't have attach_library, but also hundreds of other things. Perhaps you only want to override page.html.twig. Normally you do this in the theme. I would start with this, because it is straightforward. To get a feeling for it, remove anything from page.html.twig, so you have no menu, no blocks, nothing and put back step by step parts of the original twig. When you have the result you want you can try to move the twig to the module. But you only need this, if you want to distribute it with the module. Commented Apr 30, 2016 at 22:08