Silex/Twig: asset function

Hi

I’m trying to learn Silex/Twig, but I’ve come across a small issue… In every “tutorial” I’ve seen, the speaker uses the “asset”-function to include JS and CSS. Unfortunately, this doesn’t seem to work for me…

<link href="{{ asset('/css/index.css') }}" rel="stylesheet" media="all" />

I get the following error: “Twig_Error_Syntax: The function “asset” does not exist in “base.html” at line 8”

I can replace the css-include to the following and it works:

<link href="{{ app.request.basepath }}/css/mails.css" rel="stylesheet" media="all" />

I’m just wondering why the first piece of code isn’t working…

Thx!

Edit: I downloaded Silex fully on their site (.zip)

The asset function is defined in a “bridge” between Twig and Symfony. I’m having trouble testing at the moment, but I believe you can edit your composer.json to include symfony/twig-bridge.

Thx for the reply.

The twig-bridge is in my composer.json (also in my autoload-namespaces.php):

"symfony/twig-bridge": "2.1.*",

It’s not a show-stopper though, I’ve used the code below which seems to work. I’m just curious why the asset-function doesn’t work…

<link href="{{ app.request.basepath }}/css/index.css" rel="stylesheet" media="all" />