Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 2 Asset images

I want to add asset images in my views. But If i load the page the images won't load..

config:

framework:
    esi:             ~
    translator:      { fallback: "%locale%" }
    secret:          "%secret%"
    router:
        resource: "%kernel.root_dir%/config/routing.yml"
        strict_requirements: "%kernel.debug%"
    form:            true
    csrf_protection: true
    validation:      { enable_annotations: true }
    templating:      { engines: ['twig'], assets_version: "1.0.0" }
    default_locale:  "%locale%"
    trust_proxy_headers: false # Whether or not the Request object should trust proxy headers (X_FORWARDED_FOR/HTTP_CLIENT_IP)
    session:         ~

# Twig Configuration
twig:
    debug:            "%kernel.debug%"
    strict_variables: "%kernel.debug%"

# Assetic Configuration
assetic:
    debug:          "%kernel.debug%"
    read_from:      %kernel.root_dir%/../public_html
    write_to:       %kernel.root_dir%/../public_html
    use_controller: false
    #bundles:        [ ]
    #java: /usr/bin/java
    filters:
        cssrewrite: ~
        #closure:
        #    jar: "%kernel.root_dir%/Resources/java/compiler.jar"
        #yui_css:
        #    jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"

index.html.twig

<img src="{{ asset('images/menu-park.gif') }}">

To install the assets I run:

php app/console assets:install public_html --env=dev --symlink

Did I forget something?

like image 842
Mitchel Verschoof Avatar asked Nov 10 '12 16:11

Mitchel Verschoof


1 Answers

The assets:install public_html command copies the src/Acme/DemoBundle/Resources/public/ directory into the public_html/bundles/acmedemo/ directory. So you need to refer to that url.

For instance: You have a bundle named MvParkBundle and you have created an image menu-park.gif inside the Resources/public/images directory, you should use this code inside twig, assuming that the front controller is inside public_html too:

<img src="{{ asset('bundles/mvpark/images/menu-park.gif') }}">

If you run the assets:install public_html command, everything should be right.

like image 129
Wouter J Avatar answered Jan 02 '23 00:01

Wouter J