Created
March 14, 2014 13:18
-
-
Save vitorbrandao/9547521 to your computer and use it in GitHub Desktop.
SmartyBundle - Assign variables to every template
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 | |
namespace Vendorx; | |
class GlobalVariablesContainer | |
{ | |
protected $vars; | |
public function __construct($three = 3) | |
{ | |
$vars = array( | |
'one' => 1, | |
'two' => 2, | |
'three' => $three | |
); | |
} | |
public function getVars() | |
{ | |
return $this->vars; | |
} | |
} |
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 | |
namespace Vendorx; | |
use NoiseLabs\Bundle\SmartyBundle\Extension\AbstractExtension; | |
class GlobalVariablesExtension extends AbstractExtension | |
{ | |
public function __construct(GlobalVariablesContainer $gvc) | |
{ | |
$this->gvc = $gvc; | |
} | |
public function getGlobals() | |
{ | |
return array('_vars' => $this->gvc->getVars()); | |
} | |
public function getName() | |
{ | |
return 'vendorx_global_vars'; | |
} | |
} | |
} |
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
<?xml version="1.0" ?> | |
<container xmlns="http://symfony.com/schema/dic/services" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | |
<services> | |
<service id="vendorx.global_variables_container"> | |
</service> | |
<service id="vendorx.smartybundle_extension.globals"> | |
<argument type="service" id="vendorx.global_variables_container"> | |
<tag name="smarty.extension" /> | |
</service> | |
</services> | |
</container> |
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
<h1>One is {$_vars.one}</h1> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment