php - How to load assets from a folder other than the web default folder? -
this architecture folders :

i load picture using asset() in twig template located in
sites/sf2.local/views/index.html.twig
and picture in
sites/sf2.local/assets/img/logo_om.gif
so in config.yml have added line :
assetic: read_from: %kernel.root_dir%/../sites/sf2.local/assets/ but doesn't work, can't load picture using :
<img src="{{ asset('img/logo_om.gif') }}" alt="img" /> in twig template..
how can ?
first, think have mistaken assets assetic. twig function asset nothing more making assets absolute. not affect assets read from. described in docs:
on other hand, assetic describes compiled (and optionally filtered, merged, uglified, etc...) resources read from. applies js , css.
possible solution:
open terminal, navigate web symlink directory:
cd /.../sf2/web ln -s ../sites/sf2.local/assets/img ln -s ../sites/sf2.local/assets/js ln -s ../sites/sf2.local/assets/css now have 3 additional symlinks (not copies) in web , using asset('img/some-pic.png') targets symlinked img directory.
is symlinking acceptable?
alternative solution (whole assets):
cd /.../sf2/web ln -s ../sites/sf2.local/assets and use it:
asset('assets/img/some-pic.png')
Comments
Post a Comment