Created
April 8, 2013 09:57
-
-
Save radmiraal/5335671 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
class Tx_Something_ViewHelpers_Format_DateViewHelper extends Tx_Fluid_ViewHelpers_Format_DateViewHelper { | |
/** | |
* Render the supplied DateTime object as a formatted date. | |
* | |
* @param mixed $date either a DateTime object or a string that is accepted by DateTime constructor | |
* @param string $format Format String which is taken to format the Date/Time | |
* @return string Formatted date | |
*/ | |
public function render($date = NULL, $format = '%d-%m-%Y') { | |
if ($date === NULL) { | |
$date = $this->renderChildren(); | |
if ($date === NULL) { | |
return ''; | |
} | |
} | |
if (!$date instanceof DateTime) { | |
try { | |
$date = new DateTime($date); | |
} catch (Exception $exception) { | |
throw new Tx_Fluid_Core_ViewHelper_Exception('"' . $date . '" could not be parsed by DateTime constructor.', 1241722579); | |
} | |
} | |
return strftime($format, $date->getTimeStamp()); | |
} | |
} | |
?> |
This file contains hidden or 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
- Create a folder Classes/ViewHelpers/Format in the extension | |
- Put a file DateViewHelper.php in that folder | |
- Copy the content of the file below in there, and change Tx_Something to your needs | |
- Add the following to your Fluid template: {namespace ext=Tx_Something_ViewHelpers} (of course change Tx_Something here too) | |
- Show a date using {item.datetime -> ext:format.date(format:'%e %B %Y')} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment