简体   繁体   English

如何在所有前端页面侧边栏中显示搜索框 typo3

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

We have developed a site with typo3 v8.7.11.我们开发了一个带有 typo3 v8.7.11 的网站。 We want to display the search box in the sidebar section, for this we installed the indexed_search extension.我们想在侧边栏部分显示搜索框,为此我们安装了 indexed_search 扩展。 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. SearchController 的searchform操作都是不可缓存的。 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:现在我通常只是在我的每个页面上包含一个搜索表单,方法是将其包含在我的 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:我像这样通过 TypoScript 移交 searchPid 变量:

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:我的建议是创建一个实际包含插件的 TypoScript 对象,如下所示:

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.请注意,您应该在 Path/To/Template/Search/ 中为此 TS-Plugin 创建一个新的“Search.html”模板,这样它就不会干扰常规插件。 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.从正常内容中的搜索插件复制表单的 HTML,并将其插入到您的页面-(html-) 模板中。

  2. create a special BE-column, insert the search-plugin into this column and render this column inherited in all pages创建一个特殊的 BE-column,将 search-plugin 插入到该列中,并在所有页面中呈现该列继承

  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)制作一个在 FE 中不可见的特殊页面,您可以在其中插入搜索插件并在每个页面的呈现中包含此特殊 CE(在 typoscript 中使用 CONTENT 对象来选择该特殊 CE)

  4. include and configure the plugin in typoscript.在打字稿中包含和配置插件。 (see answer of Thomas Löffler) (见 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).我更喜欢选项 2,因为它最灵活并且不需要任何可能随时间变化的特殊页面或内容 ID(选项 3)。 It also can handle any kind of CE.它还可以处理任何类型的 CE。
Option 1 needs manual fixing if there are changes in the plugin rendering after an update for example.例如,如果更新后插件渲染发生变化,选项 1 需要手动修复。
Option 4 is not possible for each plugin or CEs at all to inherit.选项 4 不可能让每个插件或 CE 都继承。 If you can configure the plugin with typoscript it is a fine option because you do not need any record (from tt_content)如果您可以使用 typoscript 配置插件,这是一个很好的选择,因为您不需要任何记录(来自 tt_content)

for option 2:对于选项 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使用 TYPO3 扩展,可以是新开发的macina_searchbox版本的副本(fork)

Template Module : Add "Macina Searchbox" under "include static from extensions".模板模块:在“include static from extensions”下添加“Macina Searchbox”。 Use this or a similar TypoScript to include it, where '6' in this example is the search page.使用这个或类似的 TypoScript 来包含它,本例中的“6”是搜索页面。 Use your own page id instead.请改用您自己的页面 ID。

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.然后你可以编辑 macina_searchbox/Resources/Private/ 下面文件夹中的 Fluid 模板文件来修改搜索框的输出。 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.您必须改为在您的搜索页面上插入一个索引搜索插件,在此示例中它的 id=6。 SUCHE is the marker in the main template of the website. SUCHE是网站主模板中的标记。 Use your own marker.使用您自己的标记。

The easiest way is to copy the given plugin from indexed_search to a variable you use in your template.最简单的方法是将给定的插件从indexed_search复制到您在模板中使用的变量。

When you eg use FLUIDTEMPLATE:例如,当您使用 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之后,您可以分配一个单独的模板并通过使用此处可能的配置更改page.10.variable.searchBox进行其他修改: https ://docs.typo3.org/typo3cms/extensions/indexed_search/8.7/Configuration/Index.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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