Skip to content

Instantly share code, notes, and snippets.

@josefglatz
Created April 28, 2016 05:34
Show Gist options
  • Save josefglatz/1a5fc5abc62630613efb739769784cb1 to your computer and use it in GitHub Desktop.
Save josefglatz/1a5fc5abc62630613efb739769784cb1 to your computer and use it in GitHub Desktop.
TYPO3 CMS Fluid ViewHelper "StripATagsViewHelper", "Strip all anchor tags viewhelper"
<?php
namespace O10\Theme\ViewHelpers;
/**
* Removes a tags from the given string
*
* ViewHelper initially implemented to use with TYPO3 CMS 6.2.x
*/
class StripATagsViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
{
/**
* Disable the escaping interceptor because otherwise the child nodes would be escaped before this view helper
* can decode the text's entities.
*
* @var boolean
*/
protected $escapingInterceptorEnabled = false;
/**
*
* @param string $value string to format
* @return mixed
*/
public function render($value = null)
{
if ($value === null) {
$value = $this->renderChildren();
}
if (!is_string($value)) {
return $value;
}
return preg_replace('/<a[^>]+>([^<]+)<\/a>/i', '\1', $value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment