Skip to content

Commit e1987c5

Browse files
committed
handling the loading of custom default date formats
1 parent a4f34f3 commit e1987c5

File tree

5 files changed

+23
-0
lines changed

5 files changed

+23
-0
lines changed

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
"config": [
3333
{
3434
"patternExtension": "twig"
35+
"twigDefaultDateFormat": "",
36+
"twigDefaultIntervalFormat": "",
3537
"twigMacroExt": "macro"
3638
}
3739
]

src/PatternLab/PatternEngine/Twig/Loaders/FilesystemLoader.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function __construct($options = array()) {
2727
$twigLoader = new \Twig_Loader_Filesystem(array($options["templatePath"],$options["partialsPath"],$macroPath));
2828
$this->instance = new \Twig_Environment($twigLoader);
2929
$this->instance = TwigUtil::loadMacros($this->instance, "filesystem");
30+
$this->instance = TwigUtil::loadDateFormats();
3031

3132
}
3233

src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function __construct($options = array()) {
3535
$twigLoader = new \Twig_Loader_Chain(array($patternPartialLoader, $macroLoader, $patternStringLoader));
3636
$this->instance = new \Twig_Environment($twigLoader);
3737
$this->instance = TwigUtil::loadMacros($this->instance, "pattern");
38+
$this->instance = TwigUtil::loadDateFormats();
3839

3940
}
4041

src/PatternLab/PatternEngine/Twig/Loaders/StringLoader.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function __construct($options = array()) {
2929
$twigLoader = new \Twig_Loader_Chain(array($macroLoader, $stringLoader));
3030
$this->instance = new \Twig_Environment($twigLoader);
3131
$this->instance = TwigUtil::loadMacros($this->instance, "string");
32+
$this->instance = TwigUtil::loadDateFormats();
3233

3334
}
3435

src/PatternLab/PatternEngine/Twig/TwigUtil.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,24 @@
1818

1919
class TwigUtil {
2020

21+
/**
22+
* Load custom date formats for Twig
23+
* @param {Instance} an instance of the twig engine
24+
*
25+
* @return {Instance} an instance of the twig engine
26+
*/
27+
public static function loadDateFormats($instance) {
28+
29+
$dateFormat = Config::getOption("twigDefaultDateFormat");
30+
$intervalFormat = Config::getOption("twigDefaultIntervalFormat");
31+
32+
if ($dateFormat && $intervalFormat) {
33+
$instance->getExtension('core')->setDateFormat($dateFormat, $intervalFormat);
34+
}
35+
36+
return $instance;
37+
}
38+
2139
/**
2240
* Load macros for the Twig PatternEngine
2341
* @param {Instance} an instance of the twig engine

0 commit comments

Comments
 (0)