Skip to content

Instantly share code, notes, and snippets.

@LarsNieuwenhuizen
Created June 8, 2012 12:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LarsNieuwenhuizen/2895308 to your computer and use it in GitHub Desktop.
Save LarsNieuwenhuizen/2895308 to your computer and use it in GitHub Desktop.
Fluid ViewHelper for str_replace
<?php
/**
* Replacement viewhelper
*
* @package lars_development
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class Tx_ExtensionName_ViewHelpers_ReplaceStringViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
/**
* Replace the $searchFor string with $replaceString in $string
*
* @param $string string
* @param $searchFor string
* @param $replaceWith string
* @return string
*/
public function render($string, $searchFor, $replaceWith) {
return str_replace($searchFor, $replaceWith, $string);
}
}
?>
{namespace t=Tx_ExtensionName_ViewHelpers}
<t:ReplaceString string="Hello world" searchFor="world" replaceWith="universe" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment