teaminmedias-pluswerk / ke_search

Search Extension for TYPO3 Content Management System, including faceting search functions.
https://extensions.typo3.org/extension/ke_search/
GNU General Public License v3.0
35 stars 62 forks source link

Placeholder attributes not honoured in snippet #393

Closed mikestreety closed 3 years ago

mikestreety commented 3 years ago

Hey,

Thank you so much for the great search plugin - works much better (and is a lot clearer) then the indexed search.

One thing I've noticed (and apologies if the terminology isn't right) but it doesn't seem to render placeholders in the abstract/snippet?

In the setup typoscript, you can declare a constants block. This can then be used inside RTE.

E.g.

constants {
    COMPANY_NAME = mikestreety
}

When in TYPO3, you can then enter ###COMPANY_NAME### and, when rendering on the frontend, this will be replaced with mikestreety.

The KE Search caches the ###COMPANY_NAME### instead of the value in the abstract. Is this possible to resolve?

image

Thanks again for the awesome work - and again, apologies if I have slightly misunderstood or got terminology wrong!

christianbltr commented 3 years ago

Unfortunately this behaviour is "by design": ke_search indexes content directly from the database without any further processing. So no placeholders get replaced as it would happen in the TYPO3 frontend.

A workaround for this would be to add a hook which processes the content before storing it into the index and replace the placeholders there.

You could use the "modifyContentFromContentElement" hook. You can find an example in the ke_search_hooks extension (https://github.com/teaminmedias-pluswerk/ke_search_hooks).

mikestreety commented 3 years ago

Thank you!

mikestreety commented 3 years ago

As a follow up to this, I managed to resolve this last week. Just putting a note here in case anyone ends up here from searching.

In ext_localconf.php load the class:

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyContentFromContentElement'][] =
    \LiquidLight\KeSearch\Hook\ProcessPlaceholderText::class;

And in your class file:

<?php

namespace LiquidLight\KeSearch\Hook;

use TYPO3\CMS\Fluid\ViewHelpers\Format\HtmlViewHelper;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;

class ProcessPlaceholderText extends HtmlViewHelper {
    public function modifyContentFromContentElement(string &$bodytext, array $ttContentRow, $pageIndexer) {

        /**
         * Store the page text after processing
         *
         * E.g. replace ###COMPANY_NAME### with the name of the company
         */
        if (TYPO3_MODE === 'BE') {
            self::simulateFrontendEnvironment();
        }
        $contentObject = GeneralUtility::makeInstance(ContentObjectRenderer::class);
        $contentObject->start([]);
        $bodytext = $contentObject->parseFunc($bodytext, [], '< lib.parseFunc');
    }
}