How to include .css and .js files in a php file (index.html.php for example) on Symfony? (I’m using Symfony2 if that matters), I read that I must include the src/link within an asset function like follow:
<link href="<?php echo $view['assets']->getUrl('MyStyle.css') ?>" rel="stylesheet" type="text/css" />
<link href="<?php echo $view['assets']->getUrl('buttons.css') ?>" rel="stylesheet" type="text/css" />
Neither that nor the ordinary of php, worked with me.
Update: css files locate on \Bundle\Resources\public\css
You have two options:
without using assetic:
If your assets are in
src/Your/Bundle/Resources/public/, you have to call./app/console assets:install --symlink web/to create a symlink fromweb/bundle/yourbundletosrc/Your/Bundle/Resources/public/so that they are accessible from web (alternatively you could do./app/console assets:install web/to copy the files directly, without symlink.Then you could do this:
using assetic:
With assetic you don’t need to install/copy the files, assetic will do it for you:
See http://symfony.com/doc/current/cookbook/assetic/asset_management.html (click on the PHP tab on the code samples).