ReplaceMarkerViewHelper
Eigener ViewHelper für Ersetzen von Text
Dieser ViewHelper ersetzt in einem Textfeld enthaltene Marker. So kann man z.B. in einem RTE Feld den Eintrag ###time### mit einem Wert (timeUntilContinue) aus dem Fluid Template ersetzen.
<rsys:Format.ReplaceMarker marker="{ time: timeUntilContinue}">{workbook.textWait}</rsys:Format.ReplaceMarker>
Hier der ViewHelper
<?php
/* *
* This script is backported from the FLOW3 package "TYPO3.Fluid". *
* *
* It is free software; you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License, either version 3 *
* of the License, or (at your option) any later version. *
* *
* The TYPO3 project - inspiring people to share! *
* */
/**
* Replaces Markers in Text
*
* @see www.php.net/manual/function.strip-tags.php
*
* = Examples =
*
* <code title="default notation">
* <rsys:Format.ReplaceMarker marker="{ user: username}">{workbook.description}</rsys:Format.ReplaceMarker>
* </code>
* <output>
* Some Text with the marker ###user### replaced with the value of username
* </output>
*
*
* @api
*/
class Tx_Rsysworkbook_ViewHelpers_Format_ReplaceMarkerViewHelper extends Tx_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;
/**
* Escapes special characters with their escaped counterparts as needed using PHPs strip_tags() function.
*
* @param array $marker
* @see www.php.net/manual/function.strip-tags.php
* @api
*/
public function render( $marker) {
$value = $this->renderChildren();
$content = '';
// get lines
$lines = explode('###', $value);
for ($i = 0; $i < sizeof($lines); $i++) {
if($i % 2 == 0)
{
//------------------------------------
// text
//------------------------------------
$content .= $lines[$i];
}
else
{
//------------------------------------
// marker
//------------------------------------
foreach ($marker as $key => $val) {
if($key == $lines[$i]) {
$content .= $val;
}
}
}
}
return $content;;
}
}
?>