SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2012
    Posts
    41
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    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...

    Code PHP:
    <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:
    Code PHP:
    <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)

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,150
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    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.
    "First make it work. Then make it better."

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2012
    Posts
    41
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thx for the reply.

    The twig-bridge is in my composer.json (also in my autoload-namespaces.php):
    Code 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...
    Code PHP:
    <link href="{{ app.request.basepath }}/css/index.css" rel="stylesheet" media="all" />


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •