Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple ViewHelper to create facet filter links (without filling up the Routing Cache) Raw
namespace Wwwision\Test\ViewHelpers\Link;
use Neos\FluidAdaptor\Core\ViewHelper\AbstractTagBasedViewHelper;
use Neos\FluidAdaptor\Core\ViewHelper;
* Simple ViewHelper to create facet filter links
* Usage:
* <x:link.filter facetName="someFacet" facetValue="someValue" />
class FacetViewHelper extends AbstractTagBasedViewHelper
* @var string
protected $tagName = 'a';
* @return void
public function initializeArguments()
$this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor');
$this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document');
$this->registerTagAttribute('rev', 'string', 'Specifies the relationship between the linked document and the current document');
$this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document');
* @param string $facetName
* @param string $facetValue
* @return string
* @throws ViewHelper\Exception if the URI could not be resolved
public function render(string $facetName, string $facetValue)
$uriBuilder = $this->controllerContext->getUriBuilder();
try {
// Adjust those values
$uri = $uriBuilder->uriFor('facetAction', [], 'controllerName', 'packageKey');
} catch (\Exception $exception) {
throw new ViewHelper\Exception($exception->getMessage(), $exception->getCode(), $exception);
$uri .= '?' . htmlspecialchars($facetName) . '=' . htmlspecialchars($facetValue);
$this->tag->addAttribute('href', $uri);
$content = $this->renderChildren();
if ($content === null) {
$content = $facetValue;
return $this->tag->render();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.