XF 2.2 Search specific XFRM category (custom search form)

Russ

Well-known member
I'm aware the default search dropdown contains the "search this category" but we're trying to create a very specific search form that will only search the currently viewed category.

Is this possible at all with a simple edit?

This is the query for searching the specific category in the resources: ?q=test&t=resource&c[categories][0]=44&c[child_categories]=1&o=relevance

This form would be where the category id is exposed (xfrm_category_view)
 
Not sure if you managed to resolve this but you should be able to edit the PAGE_CONTAINER template and use an <xf:if is="$xf.uri == ... check to modify the search form for that category only.
 
Not sure if you managed to resolve this but you should be able to edit the PAGE_CONTAINER template and use an <xf:if is="$xf.uri == ... check to modify the search form for that category only.

Thanks Brogan, I ended up doing a bit of a messy work around. We wanted a single text box a user could type and hit enter. This seems to work in xfrm_overview_macros for anyone else.

Code:
                        <form action="{{ link('search/search') }}" method="post"
                              class="menu-content"
                              data-xf-init="quick-search">
                            <div class="menu-row">

                                <div class="inputGroup inputGroup--joined">
                                    <xf:textbox name="keywords"
                                                placeholder="{{ phrase('search') }} this category"
                                                aria-label="{{ phrase('search') }} this category"
                                                data-menu-autofocus="true" />
                                    <xf:select name="constraints"
                                               class="js-quickSearch-constraint"
                                               aria-label="{{ phrase('search_within') }}">

                                        <xf:option value="{&quot;search_type&quot;:&quot;resource&quot;,&quot;c&quot;:{&quot;categories&quot;:[{$category.resource_category_id}],&quot;child_categories&quot;:1}}">This category</xf:option>
                                    </xf:select>
                                </div>
                            </div>
                            <xf:csrf />
                        </form>
 
Back
Top Bottom