Skip to content

Commit

Permalink
get Query Param text in Searchbar todo (caching Problem)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-sc committed Oct 9, 2024
1 parent 6df21ae commit a9cb072
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
23 changes: 12 additions & 11 deletions Classes/ViewHelpers/GetQueryParamsViewHelper.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
<?php

declare(strict_types=1);

namespace Slub\LisztCommon\ViewHelpers;

use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Type\File\ImageInfo;



final class GetQueryParamsViewHelper extends AbstractViewHelper
{


public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): array
public function initializeArguments(): void
{
$this->registerArgument('param', 'string', 'Name of the parameter key', true);
}

/** @var RenderingContext $renderingContext */
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): ?string
{
$request = $renderingContext->getRequest();
$queryParams = $request->getQueryParams();

// Check if the argument param exists in the query parameters
if (array_key_exists($arguments['param'], $queryParams)) {
return $queryParams[$arguments['param']];
}

return $request->getQueryParams();

// Return null if parameter does not exist
return null;
}
}
11 changes: 5 additions & 6 deletions Resources/Private/Partials/SearchBar.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@

<f:comment>ToDo: viewHelper for SearchParams</f:comment>
<section id="searchbar" class="searchbar">

<f:debug>{lw:getQueryParams(param: 'text')}</f:debug>
<div class="container-xl">

<f:debug>{lw:getQueryParams()}</f:debug>

<form method="get" class="form-inline">
<f:comment>Todo: write a config var for serach action in form action method</f:comment>
<f:comment>Cache Problem: https://b13.com/blog/caching-in-typo3-part-1-frontend-caches</f:comment>
<form method="get" action="/bibliografie" class="form-inline">
<div class="input-group mb-3">

<input name="searchTerm" value="" class="form-control no-shadow" aria="{label:'Text input with dropdown button'}" placeholder="" />
<input name="text" value="{lw:getQueryParams(param: 'text')}" class="form-control no-shadow" aria="{label:'Text input with dropdown button'}" placeholder="" />
<button class="btn btn-outline-dark" id="button-searchBar">{f:translate(key: 'searchButtonLabel', extensionName: 'liszt_common')}
</button>
</div>
Expand Down
4 changes: 3 additions & 1 deletion ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

defined('TYPO3') or die();


// Attention! ToDo: research for disable Cache for this Controller and Searchbar
ExtensionUtility::configurePlugin(
'LisztCommon',
'SearchListing',
[ SearchController::class => 'index' ],
[ SearchController::class => '' ]
[ SearchController::class => 'index' ]
);

ExtensionManagementUtility::addPageTSConfig(
Expand Down

0 comments on commit a9cb072

Please sign in to comment.