gpt4 book ai didi

symfony - Twig 运行时错误 : Impossible to invoke a method ("test") on a string variable

转载 作者:行者123 更新时间:2023-12-04 10:06:53 25 4
gpt4 key购买 nike

我有以下 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com