This bundle offers a generic filter module to use with arbitrary contao entities containing standard filter with initial filters and filter form types including symfony form type representations.
codefog/contao-news_categories
codefog/tags-bundle
heimrichhannot/contao-categories-bundle
heimrichhannot/contao-encore-bundle
Install with composer or contao manager
composer require heimrichhannot/contao-filter-bundle
Update database
We recommend to use this bundle toghether with List Bundle and Reader Bundle.
The Wrapper element has to be places before the fields associated with them. For example the date_range wrapper element needs to be placed before the two associated date fields.
Filter Bundle Forms are not typical GET-Forms, so it is not possible to simple copy the filter urls to share or bookmark a filtered list. To overcome this limitation, preselect urls can be generated. Preselect urls for the current filter can be found within template variabled, you can create a preselect content element or get the url programmatically from the FilterConfig.
If a filter is set, the variable preselectUrl
contains the preselection url for
the current filter. It's available in the filter templates and the frontend module
template.
You can for example create a copy preselect url button:
{% if preselectUrl is defined and preselectUrl is not empty %}
<div class="col-xd-12 col-md-3">
<a class="btn btn-primary" onclick="navigator.clipboard.writeText('{{ preselectUrl }}');alert('Copied preselect link!');return false;">Filtervorauswahllink kopieren</a>
</div>
{% endif %}
You can use one of the following content elements:
You can generate the preselect link from the FilterConfig instance
<?php
use HeimrichHannot\FilterBundle\Manager\FilterManager;
class CustomController {
private FilterManager $filterManager;
public function invoke(): string
{
$filterConfig = $this->filterManager->findById($this->objModel->filter);
return !empty($filterConfig->getData()) ? $filterConfig->getPreselectAction($filterConfig->getData(), true) : ''
}
}
Insert tag | Arguments | Description |
---|---|---|
{{filter_reset_url::*::*}} |
filter ID :: page ID or alias | This tag will be replaced with a reset filter link to an internal page with (replace 1st with the filter ID, replace 2nd with the page ID or alias) |