Created
February 14, 2013 08:48
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can be used like this:
{setup.validTo -> f:format.date() -> a:default(default: 'unlimited')}