Skip to content

Instantly share code, notes, and snippets.

@kdambekalns
Created February 14, 2013 08:48
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 kdambekalns/4951396 to your computer and use it in GitHub Desktop.
Save kdambekalns/4951396 to your computer and use it in GitHub Desktop.
A Fluid ViewHelper to fall back to a default value in case a variable is empty.
<?php
namespace Api\Core\ViewHelpers;
/* *
* This script belongs to the TYPO3 Flow package "Api.Core". *
* *
* */
use TYPO3\Flow\Annotations as Flow;
/**
*
* @Flow\Scope("prototype")
*/
class DefaultViewHelper extends \TYPO3\Fluid\Core\ViewHelper\AbstractViewHelper {
/**
* Get the header include code for including Twitter Bootstrap on a page. If needed
* the jQuery library can be included, too.
*
* Example usage:
* {namespace a=Api\Core\ViewHelpers}
* {foo -> a:defaultValue('')>
*
* @param string $default
* @param string $content
* @return string
*/
public function render($default, $content = NULL) {
if ($content === NULL) {
$content = $this->renderChildren();
if ($content === NULL || $content === '') {
return $default;
}
}
return $content;
}
}
?>
@kdambekalns
Copy link
Author

Can be used like this:

{setup.validTo -> f:format.date() -> a:default(default: 'unlimited')}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment