Filtered conditions on taxonomy - possible cascade issue? #11331
-
I have the following form field, populated using a taxonomy. I am trying to use a filtering condition to only include taxonomy terms that are set to a particular provider_type (another taxonomy term selected specifically for this page). <label for="provider_categories" class="block text-sm font-medium text-gray-700">Category:</label>
<select id="provider_categories" name="provider_categories" class="mt-4 border py-2 px-4 mb-2 border-fp-blue bg-white rounded-t rounded-b w-full text-base text-fp-blue-medium" data-comparison="=" data-include-null="0">
<option value="">All</option>
{{ taxonomy:provider_categories provider_types:in="{ selected_provider_type:slug }" | sort }}
<option value="{{ slug }}" {{ if get:provider_categories == slug }}selected{{ /if }}>{{ title }}</option>
{{ /taxonomy:provider_categories }}
</select> Here is an example provider_category taxonomy term: title: Bedroom
blueprint: provider_category
provider_types:
- equipment-supplier Here is a snippet from the page entry, containing the ---
...
enable_speech: true
search_heading: 'Search for equipment suppliers'
info_banner_media_type: none
selected_provider_type: equipment-supplier
keyword_search: true
category_search: true
...
--- Here is a snippet showing how the ...
-
handle: selected_provider_type
field:
create: false
taxonomies:
- provider_types
type: terms
display: 'Selected provider type'
instructions: 'Select the provider types to display on this page.'
max_items: 1
mode: select
... If I use text instead of a variable value in the condition, such as If I change the filter to use any other field, something like Do I have some sort of cascade issue? Or am I using the filters incorrectly? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
can you remove this |
Beta Was this translation helpful? Give feedback.
-
If there are no results, the inner contents of most tags will still get evaluated to allow you the opportunity to handle the "no results" scenario; it sounds like this is what you are running into. If you add a <label for="provider_categories" class="block text-sm font-medium text-gray-700">Category:</label>
<select id="provider_categories" name="provider_categories" class="mt-4 border py-2 px-4 mb-2 border-fp-blue bg-white rounded-t rounded-b w-full text-base text-fp-blue-medium" data-comparison="=" data-include-null="0">
<option value="">All</option>
{{ taxonomy:provider_categories provider_types:in="{ selected_provider_type:slug }" }}
{{ dump }}
<option value="{{ slug }}" {{ if get:provider_categories == slug }}selected{{ /if }}>{{ title }}</option>
{{ /taxonomy:provider_categories }}
</select> You will likely see a variable named We can use this to conditionally render the inner contents: <label for="provider_categories" class="block text-sm font-medium text-gray-700">Category:</label>
<select id="provider_categories" name="provider_categories" class="mt-4 border py-2 px-4 mb-2 border-fp-blue bg-white rounded-t rounded-b w-full text-base text-fp-blue-medium" data-comparison="=" data-include-null="0">
<option value="">All</option>
{{ taxonomy:provider_categories provider_types:in="{ selected_provider_type:slug }" }}
{{ unless no_results }}
<option value="{{ slug }}" {{ if get:provider_categories == slug }}selected{{ /if }}>{{ title }}</option>
{{ /unless }}
{{ /taxonomy:provider_categories }}
</select> Alternatively, we can also alias the results using the <label for="provider_categories" class="block text-sm font-medium text-gray-700">Category:</label>
<select id="provider_categories" name="provider_categories" class="mt-4 border py-2 px-4 mb-2 border-fp-blue bg-white rounded-t rounded-b w-full text-base text-fp-blue-medium" data-comparison="=" data-include-null="0">
<option value="">All</option>
{{ taxonomy:provider_categories provider_types:in="{ selected_provider_type:slug }" as="options" }}
{{ options }}
<option value="{{ slug }}" {{ if get:provider_categories == slug }}selected{{ /if }}>{{ title }}</option>
{{ /options }}
{{ /taxonomy:provider_categories }}
</select> The aliased option is useful if you also wanted to conditionally render the select wrapper, or other custom behavior. The content inside |
Beta Was this translation helpful? Give feedback.
I think its related to the
provider_types:in
filter:Does it work if you switch it to "contains"? That way it should check if the provider type has the slug you're looking for: