Discussion:
Twig templates & absolute paths
Ruben de Vries
2011-08-17 15:27:20 UTC
Permalink
For some situations (like print / pdf generation, etc) it might be helpfull
to be able to output absolute paths in twig, unfortunatly we can't tell
either url() nor asset() (nor assetic) to output an absolute path ...

For now I've created a twig filter which uses some of the code from the
Symfony2 UrlGenerator component to create an absolute path .. but it feels
really dirty ..

any ideas?




PS. my case was for generating a PDF using
https://github.com/knplabs/KnpSnappyBundle
--
If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To post to this group, send email to symfony2-/***@public.gmane.org
To unsubscribe from this group, send email to
symfony2+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
Varga Marcell
2011-08-17 16:56:36 UTC
Permalink
You can generate absolute patch by using url() in twig like this:

<a href="{{ url(mypage) }}">LINK</a>

Marcell
Post by Ruben de Vries
For some situations (like print / pdf generation, etc) it might be helpfull
to be able to output absolute paths in twig, unfortunatly we can't tell
either url() nor asset() (nor assetic) to output an absolute path ...
For now I've created a twig filter which uses some of the code from the
Symfony2 UrlGenerator component to create an absolute path .. but it feels
really dirty ..
any ideas?
PS. my case was for generating a PDF using
https://github.com/knplabs/KnpSnappyBundle
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
--
If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To post to this group, send email to symfony2-/***@public.gmane.org
To unsubscribe from this group, send email to
symfony2+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
Ruben de Vries
2011-08-24 11:23:50 UTC
Permalink
yea using url() instead of path() works like a charm for routing, just
assets are a problem then I guess...
--
If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To post to this group, send email to symfony2-/***@public.gmane.org
To unsubscribe from this group, send email to
symfony2+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
Eric Cambray
2011-08-29 10:27:27 UTC
Permalink
I'm looking for a solution too (for absolute path in asset() )
--
If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To post to this group, send email to symfony2-/***@public.gmane.org
To unsubscribe from this group, send email to
symfony2+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
Grégoire Passault
2011-08-29 10:34:23 UTC
Permalink
You can do this :

{{ app.request.uriForPath('img/foo.jpg') }}

I don't know if there is a cleaner way for now

Greg
Post by Eric Cambray
I'm looking for a solution too (for absolute path in asset() )
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
--
Grégoire Passault
--
If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To post to this group, send email to symfony2-/***@public.gmane.org
To unsubscribe from this group, send email to
symfony2+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
Fabien Potencier
2011-08-29 10:46:24 UTC
Permalink
Post by Grégoire Passault
{{ app.request.uriForPath('img/foo.jpg') }}
For assets, you need to use this: {{ app.request.basepath }}/img/foo.jpg

Fabien
Post by Grégoire Passault
I don't know if there is a cleaner way for now
Greg
I'm looking for a solution too (for absolute path in asset() )
--
If you want to report a vulnerability issue on symfony, please send
it to security at symfony-project.com <http://symfony-project.com>
You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
--
Grégoire Passault
--
If you want to report a vulnerability issue on symfony, please send it
to security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
--
If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To post to this group, send email to symfony2-/***@public.gmane.org
To unsubscribe from this group, send email to
symfony2+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
Loading...