Symfony2 Twig including header with assets not working

回眸只為那壹抹淺笑 提交于 2019-12-24 04:31:03

问题


I'm trying to include my header into another template, not extending, like this

{% include '@Foo:Bar:_header.html.twig' %}

That header, contains this

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>{{ site.name }}</title>

    {% block stylesheets %}
        {% stylesheets
            "@Foo/Resources/public/app.css"
        %}
            <link rel="stylesheet" href="{{ asset_url }}" />
        {% endstylesheets %}
    {% endblock stylesheets %}
</head>
<body>

Nothing unusual, just some css file with assetic.

This behaviour gives throws me this exception

An exception has been thrown during the compilation of a template ("The template does not support the "bundle" parameter.") in "@Foo/bar/_header.html.twig".

huh?

If instead of including it {% include %} I extend it {% extends %} everything works perfectly.

Why I want to include instead of extend? I want to create new blocks, and include other stuff etc.

This problem is ok? Is this the way it's supossed to work?


回答1:


Silly answer, silly problem.

Fix was removing @ from include, I don't know why I used it.

{% include '@Foo:Bar:_header.html.twig' %} not working

{% include 'Foo:Bar:_header.html.twig' %} working




回答2:


See issue: https://github.com/symfony/AsseticBundle/issues/331

It states that to fix this issue you should update AsseticBundle to "master-dev" branch (this issue has been fixed few days ago, but not yet merged in a stable release of the Bundle)



来源:https://stackoverflow.com/questions/27546444/symfony2-twig-including-header-with-assets-not-working

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