{# Copyright (C) 2026 Front Matter. invenio-pidbox is free software; you can redistribute it and/or modify it under the terms of the MIT License; see LICENSE file for more details. The search form of the menubar and of the front page: a select of what to search beside the field, as on commonmeta.org. Imported with context: {% import "invenio_pidbox/search_form.html" as search with context %} {{ search.search_form(search.kind_options, "pidbox-search") }} #} {#- Works, and people, organizations and containers while their pages are on. Each kind is offered only when its profiles are switched on, because that switch is what registers the route: building the URL unconditionally raises BuildError, on every page that renders the form. `config.X` on a missing key yields Undefined, which is falsy, so this is also correct for an app that never loaded the extension. #} {%- set kind_options = [ { "key": "records", "text": _("Works"), "value": url_for("invenio_search_ui.search"), }] %} {%- if config.PIDBOX_PERSON_PROFILES %} {%- set kind_options = kind_options + [ { "key": "people", "text": _("People"), "value": url_for("invenio_pidbox.people_search"), }] %} {%- endif %} {%- if config.PIDBOX_ORGANIZATION_PROFILES %} {%- set kind_options = kind_options + [ { "key": "organizations", "text": _("Organizations"), "value": url_for("invenio_pidbox.organizations_search"), }] %} {%- endif %} {%- if config.PIDBOX_CONTAINER_PROFILES %} {%- set kind_options = kind_options + [ { "key": "containers", "text": _("Containers"), "value": url_for("invenio_pidbox.containers_search"), }] %} {%- endif %} {#- A plain form, not InvenioRDM's search bar, which offers the options only in a dropdown once something is typed; its id isn't header-search-bar, so InvenioRDM's React search bar doesn't replace it. The menubar keeps a hidden #header-search-bar for the search pages, see searchbar.html. The page's own kind is preselected, so the box on /people/ searches people. On a search page of one of the options, the box holds its query (?q=), and an × clears it: the field, and the results, which the page shows again without the query, with its filters and sort. The search goes to the chosen page with the query as ?q=; without JavaScript the form searches the preselected option. With only one option there is nothing to choose and no select. `id` names the form ("-form") and its select ("-kind"), so that it is unique on the page; `big` is the front page's larger form; `community`, a community's slug, keeps the search in that community: the people, organization and container searches take it as ?community=. #} {%- macro search_form(options, id, big=False, community=None) %} {%- set path = request.path if request else "" %} {%- set selected_key = namespace(value=options[0]["key"]) %} {%- for prefix, key in [("/people", "people"), ("/organizations", "organizations"), ("/containers", "containers")] %} {%- if path.startswith(prefix) %}{% set selected_key.value = key %}{% endif %} {%- endfor %} {%- set selected_key = selected_key.value %} {%- set selected = (options | selectattr("key", "equalto", selected_key) | first) or options[0] %} {#- The query of the search page shown, not of any page with a ?q=. #} {%- set on_search_page = path in (options | map(attribute="value") | list) %} {%- set query = (request.args.get("q") or "") if (on_search_page and request.args is defined) else "" %} {%- endmacro %}