Created
February 12, 2015 16:03
-
-
Save htuscher/b002c92554bcc1ed06c8 to your computer and use it in GitHub Desktop.
TYPO3 Solr using Fluid-Templating for results
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!defined('TYPO3_MODE')) { | |
die ('Access denied.'); | |
} | |
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['PiResults']['addViewHelpers'][] = 'ODS\\OdsSolr\\ViewHelper\\ViewHelperProvider'; | |
// Overrides Tx_Solr_Template, because we need some protected variables to inject a fluid StandaloneView | |
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']['Tx_Solr_Template']['className'] = 'ODS\\OdsSolr\\Overrides\\SolrTemplate'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Copyright notice | |
* | |
* (c) Onedrop Solutions GmbH & Co. KG, www.1drop.de | |
* | |
* @author Hans Höchtl <[email protected]> | |
* | |
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later | |
*/ | |
namespace ODS\OdsSolr\ViewHelper; | |
use TYPO3\CMS\Core\Utility\GeneralUtility; | |
/** | |
* Class FluidResult | |
* | |
* @package ODS\OdsSolr\ViewHelper | |
*/ | |
class FluidResult extends \Tx_Solr_ViewHelper_AbstractSubpartViewHelper { | |
/** | |
* constructor, takes an optional array of arguments for initialisation | |
* | |
* @param $arguments array optional initialisation arguments | |
*/ | |
public function __construct( array $arguments = array() ) { | |
} | |
/** | |
* execute method | |
* | |
* @param array array of arguments | |
* | |
* @return string The rendered output. | |
*/ | |
public function execute( array $arguments = array() ) { | |
/** @var \TYPO3\CMS\Fluid\View\StandaloneView $view */ | |
$view = GeneralUtility::makeInstance('TYPO3\\CMS\\Fluid\\View\\StandaloneView'); | |
$resourcePath = GeneralUtility::getFileAbsFileName('EXT:odssolr/Resources/Private'); | |
$view->setPartialRootPath($resourcePath . '/Partials'); | |
$view->setTemplatePathAndFilename($resourcePath . '/Templates/Solr/Results/FluidResults.html'); | |
$templateLoops = $this->getTemplate()->getLoops(); | |
$templateVars['results'] = $templateLoops['result_documents']['data']; | |
$view->assign('results', $templateLoops['result_documents']['data']); | |
$content = $view->render(); | |
return $content; | |
} | |
/** | |
* @return \ODS\OdsSolr\Overrides\SolrTemplate | |
*/ | |
public function getTemplate() { | |
return parent::getTemplate(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="row-list"> | |
<f:for each="{results}" as="result"> | |
<article> | |
<!-- | |
Score: {result.score} | |
Document ID: {result.id} | |
--> | |
<h3> | |
<a href="{result.url}">{result.title}</a> | |
</h3> | |
<p class="excerpt"> | |
<f:format.raw>{result.content}</f:format.raw> | |
</p> | |
</article> | |
<hr> | |
</f:for> | |
</div> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- ###SOLR_SEARCH_RESULTS### begin --> | |
<div class="tab-content"> | |
<div class="tab-pane active"> | |
###FLUIDRESULT:Results### | |
###FLUIDRESULT:Results### | |
</div> | |
</div> | |
###RESULTS.PAGEBROWSER### | |
</div> | |
<!-- ###SOLR_SEARCH_RESULTS### end --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Copyright notice | |
* | |
* (c) Onedrop Solutions GmbH & Co. KG, www.1drop.de | |
* | |
* @author Hans Höchtl <[email protected]> | |
* | |
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later | |
*/ | |
namespace ODS\OdsSolr\Overrides; | |
class SolrTemplate extends \Tx_Solr_Template { | |
/** | |
* @return array | |
*/ | |
public function getVariables() { | |
return $this->variables; | |
} | |
/** | |
* @return array | |
*/ | |
public function getLoops() { | |
return $this->loops; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Copyright notice | |
* | |
* (c) Onedrop Solutions GmbH & Co. KG, www.1drop.de | |
* | |
* @author Hans Höchtl <[email protected]> | |
* | |
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later | |
*/ | |
namespace ODS\OdsSolr\ViewHelper; | |
use TYPO3\CMS\Core\Utility\GeneralUtility; | |
/** | |
* Class ViewHelperProvider | |
* | |
* @package ODS\OdsSolr\ViewHelper | |
*/ | |
class ViewHelperProvider implements \Tx_Solr_ViewHelperProvider { | |
/** | |
* provides additional viewhelper objects to be added to the templating engine | |
* | |
* @param array array with a structure of view helper name => Tx_Solr_ViewHelper objects | |
* @return array | |
*/ | |
public function getViewHelpers() { | |
$fluidResult = GeneralUtility::makeInstance('ODS\\OdsSolr\\ViewHelper\\FluidResult'); | |
return array( | |
'FLUIDRESULT' => $fluidResult | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment