CropViewHelper
Eigener ViewHelper für Wort Begrenzung
Schneidet Text ab gegebener Position ab und ergänzt "...". Ganze Worte werden nicht zerschnitten sondern ausgeschrieben.
Aufruf
<rsys:Crop fieldValue="{product.description}" maxlength="140"></rsys:Crop>
Listing
<?php
/**
* This class is a demo view helper for the Fluid templating engine.
*
* @package TYPO3
* @subpackage Fluid
* @version
*/
class Tx_Rsysproductbase_ViewHelpers_CropViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
/**
* For testing view helpers implementations
*
* @param string $fieldValue text
* @param int $maxlength The number of characters of the dummy content
*
* @return string dummy content, cropped after the given number of characters
*/
public function render($fieldValue, $maxlength = 200 ) {
$value = strip_tags($fieldValue);
if (strlen($value) > $maxlength) {
$valueRestOfWord = substr($value,$maxlength);
$valueRestOfWord = substr($valueRestOfWord,0,strpos($valueRestOfWord,' ') );
$value = substr($value,0,$maxlength) . $valueRestOfWord . '...';
}
return $value;
}
}
?>