Permalink
Browse files

Add a property

  • Loading branch information...
1 parent c48a62e commit d273c2571c6dccc23456bff961f33d7e83b8abd3 @ke20 ke20 committed Mar 14, 2013
Showing with 15 additions and 5 deletions.
  1. +12 −5 Entea/Twig/Extension/AssetExtension.php
  2. +3 −0 README.md
@@ -7,24 +7,31 @@
namespace Entea\Twig\Extension;
-class AssetExtension extends \Twig_Extension {
+class AssetExtension extends \Twig_Extension
+{
private $app;
+ private $options;
- function __construct(\Silex\Application $app)
+ function __construct(\Silex\Application $app, array $options = array())
{
$this->app = $app;
+ $this->options = $options;
}
-
public function getFunctions()
{
return array(
'asset' => new \Twig_Function_Method($this, 'asset'),
);
}
- public function asset($url) {
- return sprintf('%s/%s', $this->app['request']->getBasePath(), ltrim($url, '/'));
+ public function asset($url)
+ {
+ $assetDir = isset($this->options['asset.directory']) ?
+ $this->options['asset.directory'] :
+ $this->app['request']->getBasePath();
+
+ return sprintf('%s/%s', $assetDir, ltrim($url, '/'));
}
/**
View
@@ -32,6 +32,9 @@ And then, in your twig file:
{{asset('/style/hello.css')}}
```
+### Properties
+ - **asset.directory**: Your asset directory
+
### Installation
#### Via composer:

0 comments on commit d273c25

Please sign in to comment.