Skip to content

Instantly share code, notes, and snippets.

@Gong-Bao-Chicken
Last active September 9, 2020 08:47
Show Gist options
  • Save Gong-Bao-Chicken/d641fc92aba46e2124aa9be70d9c4a72 to your computer and use it in GitHub Desktop.
Save Gong-Bao-Chicken/d641fc92aba46e2124aa9be70d9c4a72 to your computer and use it in GitHub Desktop.
How to Create a (global) Search Box for Typo3 7,8 and probably 9
plugin.tx_indexedsearch {
show {
rules=0
}
settings {
targetPid = YOURPID
displayRules = 0
exactCount = 1
}
view {
partialRootPaths {
0 = EXT:indexed_search/Resources/Private/Partials/
10 = {$plugin.tx_indexedsearch.view.partialRootPath}
20 = EXT:yourdistribution/Resources/Private/Extensions/indexed_search/Partials/
}
}
}
plugin.tx_indexedsearch._DEFAULT_PI_VARS.lang = 0
plugin.tx_indexedsearch.settings.defaultOptions.languageUid = 0
// english
[globalVar = GP:L = 3]
plugin.tx_indexedsearch._DEFAULT_PI_VARS.lang = 3
plugin.tx_indexedsearch.settings.defaultOptions.languageUid = 3
[global]
// french
[globalVar = GP:L = 4]
plugin.tx_indexedsearch._DEFAULT_PI_VARS.lang = 4
plugin.tx_indexedsearch.settings.defaultOptions.languageUid = 4
[global]

Basic File Structure:

YOURDISTRIBUTION
.
├── Configuration
│   ├── RTE
│   ├── TSconfig
│   └── TypoScript
│       ├── Extensions
│       │   └── 0020_plugin.indexedsearch.ts
│       ├── Library
│       │   ├── 0060_lib.searchbox.ts
│       └── setup.txt
├── Resources
│   ├── Private
│   │   ├── Extensions
│   │   │   └── indexed_search
│   │   │       ├── Partials (<To overwrite the style of the search Page)
│   │   │       │   ├── Form.html
│   │   │       │   ├── Rules.html
│   │   │       │   └── Searchresult.html
│   │   ├── Layouts
│   │   ├── Partials
│   │   │   ├── Searchbox.html (< To overwrite only the searchbox as a partial)
│   │   └── Templates
│   └── Public
│       ├── Css
│       ├── avatars
│       ├── img
│       └── js
└── ext_localconf.php

The only other guide that helped me was this: http://www.typo3-probleme.de/2016/04/29/typo3-7-6-indexed_search-template-auslagern-und-erweitern-1804/ .Things to note:

/Partials/Form.html

 <f:form action="{settings.action}" method="post" pluginName="{settings.pluginName}" extensionName="{settings.extensionName}" absolute="true" controller="{settings.controller}" id="tx_indexedsearch_searchbox" pageUid="{settings.targetPid}" noCacheHash="{settings.hash}">

The parameters for the f:form have to be provided as action, method, pluginName, extensionName etc... to build the correct query string.

class="tx-indexedsearch_searchbox"

And

id="tx_indexedsearch_pointer_searchbox"

Make sure to check ALL id's and css classes. Indexed Search doesnt like duplicates.

lib.searchbox = FLUIDTEMPLATE
lib.searchbox {
templateName = Searchbox
settings {
languageid = {plugin.tx_indexedsearch._DEFAULT_PI_VARS.lang}
targetPid = YOURPID
controller = Search
action = search
pluginName = pi2
extensionName = indexedsearch
hash = false
}
templateRootPaths {
0 = EXT:indexed_search/Resources/Private/Partials/
10 = {$plugin.tx_indexedsearch.view.partialRootPath}
20 = EXT:yourdistribution/Resources/Private/Partials/
}
}
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<div class="tx-indexedsearch_searchbox">
<f:form action="{settings.action}" method="post" pluginName="{settings.pluginName}" extensionName="{settings.extensionName}" absolute="true" controller="{settings.controller}" id="tx_indexedsearch_searchbox" pageUid="{settings.targetPid}" noCacheHash="{settings.hash}">
<div class="tx-indexedsearch-hidden-fields">
<f:form.hidden name="search[_sections]" value="0"/>
<f:form.hidden name="search[_freeIndexUid]" id="tx_indexedsearch_freeIndexUid_searchbox" value="_"/>
<f:form.hidden name="search[pointer]" id="tx_indexedsearch_pointer_searchbox" value="0"/>
<f:form.hidden name="search[ext]" value="{settings.ext}"/>
<f:form.hidden name="search[searchType]" value="{settings.searchType}"/>
<f:form.hidden name="search[defaultOperand]" value="{settings.defaultOperand}"/>
<f:form.hidden name="search[mediaType]" value="{settings.mediaType}"/>
<f:form.hidden name="search[sortOrder]" value="{settings.sortOrder}"/>
<f:form.hidden name="search[group]" value="{settings.group}"/>
<f:form.hidden name="search[languageUid]" value="{settings.languageUid}"/>
<f:form.hidden name="search[desc]" value="{settings.desc}"/>
<f:form.hidden name="search[numberOfResults]" value="{settings.numberOfResults}"/>
<f:form.hidden name="search[extendedSearch]" value="{settings.extendedSearch}"/>
</div>
<div class="tx-indexedsearch-form pull-xs-right" style="color: black;">
<!--<label for="tx-indexedsearch-searchbox-sword">-->
<!--<f:translate key="form.searchFor"/>-->
<!--:</label>-->
<f:form.textfield name="search[sword]" value="{sword}" id="tx-indexedsearch-searchbox-sword_searchbox"
class="tx-indexedsearch-searchbox-sword"/>
</div>
<!--<div class="tx-indexedsearch-search-submit">-->
<!--<f:form.submit name="search[submitButton]" value="{f:translate(key: 'form.submit')}"-->
<!--id="tx-indexedsearch-searchbox-button-submit" class="tx-indexedsearch-searchbox-button"/>-->
<!--</div>-->
</f:form>
</div>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment