作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下 Twig 模板(代码在同一个文件中):
{% macro renderJob(fields) %}
// renders the job UI block, but I've removed it for simplicity
Hello world.
{% endmacro %}
{% block _jobs_widget %}
<div id="jobsContainer">
{% for fields in form.children %}
{% dump fields %}
{{ _self.renderJob(fields) }}
{% endfor %}
</div>
{% endblock %}
twig/twig = v2.1.0
后我收到以下错误:
Impossible to invoke a method ("renderJob") on a string variable ("@AppBundle/Jobs/form/job.html.twig").
1.3.x
中工作得很好.
fields
变量包含正确的数据,但它似乎无法将其传递给
renderJob
宏还是找不到宏(这有点奇怪)?
最佳答案
您是否尝试过以下方法?
{% import _self as renderJobMacro %}
{% macro renderJob(fields) %}
// renders the job UI block, but I've removed it for simplicity
Hello world.
{% endmacro %}
{% block _jobs_widget %}
<div id="jobsContainer">
{% for fields in form.children %}
{{ renderJobMacro.renderJob(fields) }}
{% endfor %}
</div>
{% endblock %}
关于symfony - Twig 运行时错误 : Impossible to invoke a method ("test") on a string variable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42484037/
我是一名优秀的程序员,十分优秀!