Symfony2 Twig including header with assets not working
Asked Answered
E

2

2

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?

En answered 18/12, 2014 at 12:17 Comment(2)
Is this template`s bundle added to assetic bundles?Begotten
@SimeonKolev #bundles: [ ] this is what I have, I've always used it like this. If this were the problem, it wouldn't work even with {%extends%} but it is working that way, and the error would be something like Add this bundle to your assetic config (or something like that, I don't remember exactly)En
E
3

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

En answered 18/12, 2014 at 14:57 Comment(1)
Take care if you use this syntax inside bundle the template will not be overridable outside of this bundle.Iver
A
0

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)

Alainealair answered 13/1, 2015 at 10:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.