-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtension.php
More file actions
99 lines (82 loc) · 2.14 KB
/
Copy pathExtension.php
File metadata and controls
99 lines (82 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
// Site Address extension for Bolt
namespace Bolt\Extension\DanielKulbe\SiteAddress;
use Symfony\Component\Intl\Intl as Intl;
class Extension extends \Bolt\BaseExtension
{
/**
* Extension name
*
* @var string
*/
const NAME = 'Site Address';
/**
* Add Twig settings in 'frontend' environment
*
* @return void
*/
public function initialize()
{
// Frontend
if ($this->app['config']->getWhichEnd() == 'frontend')
{
// Add Twig template path
$this->app['twig.loader.filesystem']->addPath(dirname(__FILE__) . '/assets');
// Add Twig functions
$this->addTwigFunction('address', 'siteAddress');
// Add Twig filter
$this->addTwigFilter('country', 'countryName');
}
}
/**
* Get the extension's human readable name
*
* @return string
*/
public function getName()
{
return Extension::NAME;
}
/**
* Set the defaults for configuration parameters
*
* @return array
*/
protected function getDefaultConfig()
{
return array(
'name' => "John Bolt",
'address' => array(
"street" => "Collstreet 23",
"zip" => "00000",
"city" => "Example Vill",
"country" => "US"
),
'phone' => "+49 (0) 00.00 00 00 00",
'mobile' => "+49 (0) 000.00 00 00",
'mail' => "me@example.com",
'template' => "address.twig"
);
}
/**
* Returns the human readable country name from a given country code.
*
* @return string
*/
public function countryName($countryCode)
{
return Intl::getRegionBundle()->getCountryName($countryCode);
}
/**
* Render the template
*
* @return string
*/
public function siteAddress ()
{
$twigValues = $this->config;
unset($twigValues['template']);
$str = $this->app['render']->render($this->config['template'], $twigValues);
return new \Twig_Markup($str, 'UTF-8');
}
}