TYPO3 v8.7.11:如何在所有前端页面侧边栏显示搜索框
Got it, let's get that indexed_search box into your sidebar on every frontend page in TYPO3 v8.7.11. Since you already have the extension installed, here's a straightforward, step-by-step guide to make this happen:
First, you need to define a reusable TypoScript object that calls the indexed_search search form. Head to your template's Setup section and add this code:
lib.searchBox = USER lib.searchBox { userFunc = TYPO3\CMS\IndexedSearch\Controller\SearchController->searchFormAction # Optional: Uncomment and adjust if you want to use a custom template for styling # templateFile = fileadmin/templates/custom_search_form.html }
This creates a lib.searchBox object that renders the default search form. If you need to tweak the HTML structure for your site's design, uncomment the templateFile line and point it to your own HTML template.
Next, you need to add this object to your sidebar layout. The exact code depends on how your template is structured:
If using a TypoScript-based template:
If your template uses marks (like page.10.marks.sidebar) for the sidebar, add this to your Setup:
# Replace "sidebar" with your actual sidebar mark name page.10.marks.sidebar < lib.searchBox # If your sidebar already has content, use += to append instead: # page.10.marks.sidebar += USER # page.10.marks.sidebar.10 < lib.searchBox
If using a Fluid template:
Open your sidebar's Fluid template file (e.g., Resources/Private/Partials/Sidebar.html) and add this ViewHelper where you want the search box to appear:
<f:cObject typoscriptObjectPath="lib.searchBox" />
Finally, confirm your template setup is inherited across all pages:
- Go to the Template module in the TYPO3 backend.
- Select your root template and check the Include static (from extensions) section—ensure
Indexed Searchis checked (this loads the extension's base TypoScript). - Verify that all child pages are using this root template (or inherit from a template that includes your search box code).
- Styling: The default search form uses the
.tx-indexedsearch-formCSS class. Add custom CSS to your site to match your sidebar's design (e.g., adjust input width, button styling). - Testing: After setting up, refresh your frontend pages to confirm the search box shows up in the sidebar, and test that searching redirects to the results page correctly.
内容的提问来源于stack exchange,提问作者raj

