简体   繁体   English

树枝变量不会通过-symfony奏鸣曲

[英]twig variable won't pass - symfony sonata

5 days have gone by, still no success! 5天过去了,仍然没有成功!

I dumped the results of my card variable and it returns results. 我转储了card变量的结果,它返回结果。

But when I try to pass it trough varibale on my twig tamplate it throws: 但是,当我尝试通过树枝状模板上的低谷槽时,它会抛出:

Variable "card" does not exist. 变量“卡”不存在。

It's defined in SonataAdmin. 它在SonataAdmin中定义。

protected function configureShowFields(ShowMapper $showMapper)
{

    $card = $this->getCardTransactions(); // on dump(), it works

    $showMapper->tab('Cards')
                    ->add('Data', 'string', array(
                        'template' => "@AdminTemplates/sonata/details.html.twig",
                        'card' => $card
                    ))
                    ->end()
                ->end();
}

and in my twig; 在我的树枝上

 {% for c in card %}
      {{ c.id }}
  {% endfor %}

I think it has to do with SonataAdmin and how it handles this type of calls but I have read the documentation and searched online but still no luck. 我认为它与SonataAdmin及其处理此类呼叫的方式有关,但我已阅读文档并在线搜索,但仍然没有运气。

You have to use the field_description.options object in your template to access your variable. 您必须在模板中使用field_description.options对象来访问变量。

protected function configureShowFields(ShowMapper $showMapper)
{

    $showMapper
        ->tab('Cards')
            ->add('Data', 'string', [
                'template' => "@AdminTemplates/sonata/details.html.twig",
                'card' => $this->getCardTransactions(),
            ])
        ->end();
}
{# @AdminTemplates/sonata/details.html.twig #}
{% extends '@SonataAdmin/CRUD/base_show_field.html.twig' %}

{%- block field -%}
    {% spaceless %}
        {% for card in field_description.options.cards %}
            {{ card.id }}
        {% else %}
            <p>No card</p>
        {% endfor %}
    {% endspaceless %}
{%- endblock -%}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM