Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including a non-twig file from twig

Tags:

twig

symfony

I need to include the contents of a file (inside my resources folder) inside a Twig template.

I have tried this with no luck:

{% include 'public/directory/file.ext' %}

Isn't Twig capable of this? (I don't want to use Assetic)

like image 660
David Morales Avatar asked Dec 20 '11 15:12

David Morales


People also ask

What is raw in Twig?

3. raw. By default, everything in Twig gets escaped when automatic escaping is enabled. If you don't want to escape a variable you'll have to explicitly mark it as safe which you can do by using the raw filter.

How do I get the current URL in Twig?

You can get the current URL in Twig/Silex 2 like this: global. request. attributes. get('_route') .


2 Answers

New in version 1.15: The source function was added in Twig 1.15. The source function returns the content of a template without rendering it

http://twig.sensiolabs.org/doc/functions/source.html

like image 72
Disparity Avatar answered Oct 16 '22 16:10

Disparity


I made a bundle just for this some time ago. It's pretty much a wrapper for file_get_contents.

The setup can be found here.

like image 38
kgilden Avatar answered Oct 16 '22 16:10

kgilden