Hi guys. I'm new to symfony and twig, and what I'm trying to do is this:
In my base.html.twig file, which I am trying to include ("article.html.twig"), everything works fine until I try to redefine (expand) the style sheet block that is in the base.html.twig file from article .html.twig.
I get an error that this can only be achieved if I extend base.html.twig (I know that it works like that, but that’s not what I want)
I want to actually attach .html.twig css and javascript to the html related article in this template and that they are only anchored (loaded by the browser) in the page section whenever I include the template in any other template. It should work as a standalone component (web page) or whatever it is called.
Do any of you know if this is possible?
Thanks in advance.
Here is base.html.twig:
<!DOCTYPE html>
<head>
<meta charset="UTF-8" />
{% block stylesheets %}
<link rel="stylesheet" type="text/css" media="all" href="{{ asset('style.css') }}" />
{% endblock %}
</head>
<body>
<p>Test include:</p>
{{ include('article.html.twig') }}
</body>
Here is article.html.twig
{% block stylesheets %}
{{ parent() }}
<link rel="stylesheet" type="text/css" media="all" href="{{ asset('custom.css') }}" />
{% endblock %}
<div id="article">
This is an Article!
</div>
source
share