ew_base/Classes/ViewHelpers/TrimViewHelper.php
2024-12-26 21:44:19 +01:00

47 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
/*
* This file is developed by evoWeb.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/
namespace Evoweb\EwBase\ViewHelpers;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
class TrimViewHelper extends AbstractViewHelper
{
/**
* @var bool
*/
protected $escapeOutput = false;
public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('content', 'string', 'Content to be trimmed');
$this->registerArgument('characters', 'string', 'Characters to be removed');
}
public function render(): string
{
$content = $this->arguments['content'] ?: $this->renderChildren();
$characters = $this->arguments['characters'] ?: null;
if ($characters !== null) {
$content = trim($content, $characters);
} else {
$content = trim($content);
}
return $content;
}
}