# Filtro Inteligente

{% hint style="info" %}
**Disponível nas páginas:** catalog | search | home\
**Para saber mais sobre como gerenciar os Filtros Inteligentes acesse:** Filtro Inteligente
{% endhint %}

{% hint style="warning" %}
**Atenção!** Esse recurso será depreciado em breve. Por favor, utilize a [nova versão](https://partners.tray.com.br/themes/construindo-seu-template/referencias/componentes/novo-filtro-inteligente).
{% endhint %}

Snippet para criar um filtro inteligente

```html
{#
# Smart Filter
# elements/snippets/smart_filter.html
#}

{% if filters %}

<form name="form-filter" method="get">
    <input type="hidden" name="loja" value="{{ store.id }}">
    {% if search.word %}
      <input name="palavra_busca" type="hidden" value="{{ search.word }}">
    {% endif %}

    {% if category.id %}
        <input type="hidden" name="categoria" value="{{ category.id }}">
    {% endif %}

    {% if filters.applied %}
        <h3>Filtros Aplicados</h3>
        <ul>
            {% for applied in filters.applied %}
                {% for item in applied %}
                    <li>
                    <a href="{{ item.url }}">{{ item.title }}</a>
                    </li>
                {% endfor %}
            {% endfor %}
        </ul>
    {% endif %}

    {% for myFilter in filters %}

        {% if myFilter.items %}

            <h3>{{ myFilter.title }}</h3>
            <ul>
            {% for item in myFilter.items %}
                <li>
                    {% if item.type == "link" %}
                        <a href="{{ item.url }}">{{ item.title }}</a>
                    {% endif %}

                    {% if item.type == "checkbox" %}
                        <label>
                            {% set checked = item.applied ? 'checked="checked"' %}
                            <input type="checkbox" name="{{ item.name }}" value="{{ item.value }}" {{ checked }} />
                            {{ item.title }}
                        </label>
                    {% endif %}
                </li>
            {% endfor %}
            </ul>

        {% elseif myFilter|length %}

           {% for var in myFilter %}

               <h3>{{ var.title }}</h3>
               <ul>
                   {% for item in var.items %}
                   <li>
                       {% if item.type == "link" %}
                       <a href="{{ item.url }}">{{ item.title }}</a>
                       {% endif %}

                       {% if item.type == "checkbox" %}
                       <label>
                           {% set checked = item.applied ? 'checked="checked"' %}
                           <input type="checkbox" name="{{ item.name }}" value="{{ item.value }}" {{ checked }} />
                           {{ item.title }}
                       </label>
                       {% endif %}
                   </li>
                   {% endfor %}
               </ul>

           {% endfor %}

        {% endif %}

    {% endfor %}

    <button type="submit" class="filter-button">{{ Translation('filtrar') }}</button>
</form>

{% endif %}
```

### Como usar <a href="#como-usar" id="como-usar"></a>

Copie o código acima e crie um arquivo separado, ex: `elements/snippets/smart_filter.html`

Faça a chamada desse arquivo onde desejar:

```twig
{% element('snippets/smart_filter') %}
```

Para saber mais sobre como gerenciar os Filtros Inteligentes acesse a documentação <https://basedeconhecimento.tray.com.br/hc/pt-br/articles/6734661410715-Novo-sistema-de-Busca-e-Filtro-Inteligente>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://partners.tray.com.br/themes/construindo-seu-template/referencias/componentes/filtro-inteligente.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
