简体   繁体   中英

How to display search box in all the frontend page sidebar typo3

We have developed a site with typo3 v8.7.11. We want to display the search box in the sidebar section, for this we installed the indexed_search extension. B

How to display a search box in all the frontend page sidebar section?

Edit:

The search and form action of the SearchController are both non-cacheable. This means that you would place a non-cacheable plugin on each of your pages, if you used my old answer. This harms performance and could have other side-effects.

Nowadays I usually simply include a search form on each of my pages by including this in my Fluid Template:

<form action="{f:uri.action(controller: 'Search', action: 'search', extensionName: 'indexedsearch', pluginName: 'Pi2', pageUid: searchPid)}" method="POST" role="search">
    <input type="text" name="tx_indexedsearch_pi2[search][sword]"  spellcheck="false" autocomplete="off" />
    <button type="submit">Search</button>
</form>

I hand over the searchPid variable via TypoScript like this:

page.10.variables.searchPid = TEXT
page.10.variables.searchPid.value = <Pid where search results should be displayed>

Old answer:

My tip would be to create a TypoScript object that actually includes the plugin, like this:

lib.headerSearch = USER
lib.headerSearch {
    userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
    extensionName = IndexedSearch
    pluginName = Pi2
    vendorName = TYPO3\CMS
    switchableControllerActions {
        Search {
            1 = form
            2 = search
        }
    }
    features {
        requireCHashArgumentForActionArguments = 0
    }
    view < plugin.tx_indexedsearch.view
    view.partialRootPaths.10 = Path/To/Partial/
    view.templateRootPaths.10 = Path/To/Template/

    settings =< plugin.tx_indexedsearch.settings
}

Then, in your template, include it like this

<f:cObject typoscriptObjectPath="lib.headerSearch" />

Note that you should create a new "Search.html" Template in Path/To/Template/Search/ for this TS-Plugin, so that it does not interfere with the regular plugin. Also, be careful if you include the search slot on the same page as the search Plugin itself.

you have multiple options:

  1. copy the HTML of the form from the search plugin in the normal content and insert it in your page-(html-)template.

  2. create a special BE-column, insert the search-plugin into this column and render this column inherited in all pages

  3. make a special page not visible in FE, where you insert the search-plugin and include this special CE in the rendering of every page (use a CONTENT object in typoscript to select that special CE)

  4. include and configure the plugin in typoscript. (see answer of Thomas Löffler)

I prefer option 2 as it is most flexible and does not need any special page or content IDs, which might change with time (option 3). It also can handle any kind of CE.
Option 1 needs manual fixing if there are changes in the plugin rendering after an update for example.
Option 4 is not possible for each plugin or CEs at all to inherit. If you can configure the plugin with typoscript it is a fine option because you do not need any record (from tt_content)

for option 2:

temp.inheritedContent = CONTENT
temp.inheritedContent {
    table = tt_content
    select.orderBy = sorting
    // -- use your own column id: --
    select.where = colPos = 100
    select.languageField = sys_language_uid
    slide = -1
}

Use a TYPO3 extension, which can be a copy (fork) of the newly developed version of macina_searchbox

Template Module : Add "Macina Searchbox" under "include static from extensions". Use this or a similar TypoScript to include it, where '6' in this example is the search page. Use your own page id instead.

Constants:

lib.macina_searchbox {
   pidSearchpage = 6
}

Setup:

10 = TEMPLATE
10.template = FILE
10.template.file = fileadmin/template/template.html
10.workOnSubpart = DOKUMENT
10.marks {
   SUCHE < lib.macina_searchbox
   LOGO = TEXT
   LOGO.value = <a href="/" title="Startseite"><img src="fileadmin/template/img/logo.png"></a>


 NAVI= HMENU
 NAVI {

Then you can edit the Fluid template files in the folders below macina_searchbox/Resources/Private/ to modify the output of the searchbox. This method is necessary in order that the search result list will not be shown on the page. You must instead insert an Indexed Search plugin on your search page, which has id=6 in this example. SUCHE is the marker in the main template of the website. Use your own marker.

The easiest way is to copy the given plugin from indexed_search to a variable you use in your template.

When you eg use FLUIDTEMPLATE:

page.10 = FLUIDTEMPLATE
page.10.variable.searchBox < plugin.tx_indexedsearch

After that you can assign a separate template and make other modifications by changing page.10.variable.searchBox with the possible configuration here: https://docs.typo3.org/typo3cms/extensions/indexed_search/8.7/Configuration/Index.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM