Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
944c118b
Commit
944c118b
authored
Aug 22, 2015
by
Fabien Potencier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added support for HTTP foundation Twig extension
parent
48a3fdc4
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
0 deletions
+20
-0
doc/providers/twig.rst
doc/providers/twig.rst
+2
-0
src/Silex/Provider/TwigServiceProvider.php
src/Silex/Provider/TwigServiceProvider.php
+3
-0
tests/Silex/Tests/Provider/TwigServiceProviderTest.php
tests/Silex/Tests/Provider/TwigServiceProviderTest.php
+15
-0
No files found.
doc/providers/twig.rst
View file @
944c118b
...
...
@@ -61,6 +61,8 @@ some Symfony components and Twig. Add it as a dependency:
When present, the ``TwigServiceProvider`` will provide you with the following
additional capabilities:
* **absolute_url()** and **relative_path()** Twig functions.
* **UrlGeneratorServiceProvider**: If you are using the
``UrlGeneratorServiceProvider``, you will have access to the ``path()`` and
``url()`` functions. You can find more information in the `Symfony Routing
...
...
src/Silex/Provider/TwigServiceProvider.php
View file @
944c118b
...
...
@@ -17,6 +17,7 @@ use Symfony\Bridge\Twig\Extension\RoutingExtension;
use
Symfony\Bridge\Twig\Extension\TranslationExtension
;
use
Symfony\Bridge\Twig\Extension\FormExtension
;
use
Symfony\Bridge\Twig\Extension\SecurityExtension
;
use
Symfony\Bridge\Twig\Extension\HttpFoundationExtension
;
use
Symfony\Bridge\Twig\Extension\HttpKernelExtension
;
use
Symfony\Bridge\Twig\Form\TwigRendererEngine
;
use
Symfony\Bridge\Twig\Form\TwigRenderer
;
...
...
@@ -52,6 +53,8 @@ class TwigServiceProvider implements ServiceProviderInterface
}
if
(
class_exists
(
'Symfony\Bridge\Twig\Extension\RoutingExtension'
))
{
$twig
->
addExtension
(
new
HttpFoundationExtension
(
$app
[
'request_stack'
]));
if
(
isset
(
$app
[
'url_generator'
]))
{
$twig
->
addExtension
(
new
RoutingExtension
(
$app
[
'url_generator'
]));
}
...
...
tests/Silex/Tests/Provider/TwigServiceProviderTest.php
View file @
944c118b
...
...
@@ -52,4 +52,19 @@ class TwigServiceProviderTest extends \PHPUnit_Framework_TestCase
};
$this
->
assertEquals
(
'foo'
,
$app
[
'twig.loader'
]
->
getSource
(
'foo'
));
}
public
function
testHttpFoundationIntegration
()
{
$app
=
new
Application
();
$app
[
'request_stack'
]
->
push
(
Request
::
create
(
'/dir1/dir2/file'
));
$app
->
register
(
new
TwigServiceProvider
(),
array
(
'twig.templates'
=>
array
(
'absolute'
=>
'{{ absolute_url("foo.css") }}'
,
'relative'
=>
'{{ relative_path("/dir1/foo.css") }}'
,
),
));
$this
->
assertEquals
(
'http://localhost/dir1/dir2/foo.css'
,
$app
[
'twig'
]
->
render
(
'absolute'
));
$this
->
assertEquals
(
'../foo.css'
,
$app
[
'twig'
]
->
render
(
'relative'
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment