Php 我想避免重复按钮

Php 我想避免重复按钮,php,symfony,Php,Symfony,我显示类别的内容,如果我有其他内容,但按钮已根据类别中的广告数量进行标记,我会显示“显示更多”按钮,当我将按钮粘贴到“for”外部时,即使类别内容为空,我也会始终获得此按钮 <div class="pedagogical pedagogical--category js-pedagogical-items" data-type="category" data-nbdisplayed="4"> {% for categoryId in questionCategori

我显示类别的内容,如果我有其他内容,但按钮已根据类别中的广告数量进行标记,我会显示“显示更多”按钮,当我将按钮粘贴到“for”外部时,即使类别内容为空,我也会始终获得此按钮

 <div class="pedagogical pedagogical--category js-pedagogical-items" data-type="category" data-nbdisplayed="4">
        {% for categoryId in questionCategories %}
            <div class="row pedagogical__items" data-type="category" data-value="{{ categoryId }}">
                {% for tool in tools if tool.questionCategory == categoryId %}
                    <div class="col-12 col-md-6 pedagogical__item__wrapper">
                        {% include 'components/tool-preview-item.html.twig' with {'tool' : tool} %}
                    </div>
                    <div class="col-12 text-center">
                        <button class="btn btn-outline-secondary js-show-more" data-type="category" data-value="{{ categoryId }}">{{ 'show-more'|trans({}, 'action') }}</button>
                    </div>
                {% endfor %}
            </div>
        {% endfor %}
    </div>

{questionCategories%%中categoryId的%
{如果tool.questionCategory==categoryId%},则工具中的工具为%
{%include'components/tool preview item.html.twig'和{'tool':tool}%}
{{'show more'{}trans({},'action')}
{%endfor%}
{%endfor%}

我认为您只需要在呈现按钮之前添加一个复选框:

<div class="pedagogical pedagogical--category js-pedagogical-items" data-type="category" data-nbdisplayed="4">
    {% for categoryId in questionCategories %}
        <div class="row pedagogical__items" data-type="category" data-value="{{ categoryId }}">
            {% set has_items = 'false' %}
            {% for tool in tools if tool.questionCategory == categoryId %}
                {% set has_items = 'true' %}
                <div class="col-12 col-md-6 pedagogical__item__wrapper">
                    {% include 'components/tool-preview-item.html.twig' with {'tool' : tool} %}
                </div>
            {% endfor %}
            {% if has_items == 'true' %}
                <div class="col-12 text-center">
                    <button class="btn btn-outline-secondary js-show-more" data-type="category" data-value="{{ categoryId }}">{{ 'show-more'|trans({}, 'action') }}</button>
                </div>
            {% endif %}
        </div>
    {% endfor %}
</div>

{questionCategories%%中categoryId的%
{%set有_项='假'%}
{如果tool.questionCategory==categoryId%},则工具中的工具为%
{%set有_项='真'%}
{%include'components/tool preview item.html.twig'和{'tool':tool}%}
{%endfor%}
{%if has_items='true%}
{{'show more'{}trans({},'action')}
{%endif%}
{%endfor%}

那个流浪的
{%else%}
在上面干什么?无论如何,在工具
中为类似“containsTools”的循环设置一个变量,然后在该循环完成后,检查该变量是否已设置,如果已设置,然后按下按钮。我粘贴代码时出错,现在修复了它,但我没有得到解决方案?