Symfony2 Twig包含资产不能正常工作的标头 [英] Symfony2 Twig including header with assets not working
问题描述
我试图将我的标题包含到另一个模板中,未扩展,就像这样
{%include'@Foo:Bar:_header.html.twig'%}
包含这个
<!DOCTYPE html>
< html lang =en>
< head>
< meta charset =utf-8>
< meta http-equiv =X-UA-Compatiblecontent =IE = edge>
< meta name =viewportcontent =width = device-width,initial-scale = 1>
< meta name =descriptioncontent =>
< meta name =authorcontent =>
< title> {{site.name}}< / title>
{%block stylesheets%}
{%stylesheets
@ Foo / Resources / public / app.css
%}
{%endstylesheets%}
{%endblock stylesheets%}
< / head>
< body>
没什么特别的,只是一些带有资产的css文件。
这种行为给我抛出这个异常
$ b
在编译模板
(
@ Foo / bar / _header.html.twig。
$ b $模板不支持bundle参数。 b
huh
如果不包括 {%include%}
我扩展它 {%extends%}
一切正常。
这个问题没关系?这是它的工作方式吗?
<愚蠢的答案,愚蠢的问题。
Fix是从包含中删除 @
,我不知道为什么我使用它。
{%include'@Foo:Bar:_header.html.twig'%}
无法使用
{%include'Foo:Bar:_header.html.twig'%}
工作
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?
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
这篇关于Symfony2 Twig包含资产不能正常工作的标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!