Reputation: 21
Here are my files configured to make every thing functionnal (but it's not ). I did a cache clear, a php app/console assests:intall web
, nothing new. Always getting this error message: Cannot load resource "."
.
twig:
paths:
"%kernel.root_dir%/../src/Acme/TestBundle": AcmeTestBundle
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [AcmeTestBundle]
assetic:
use_controller: false
_assetic:
resource: .
type: assetic
{% javascripts '@AcmeTestBundle/Resources/public/js/main.js' %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
console.log('hello');
Does anyone know if I'm missing something in the config or in my twig files to make the route finally findable :P ? Thank you guys.
Upvotes: 0
Views: 2235
Reputation: 239
try to configure like this:
1- Put your resources in the "public" folder, is found in:
YourBundle/Resources/config/public/css
YourBundle/Resources/config/public/js
YourBundle/Resources/config/public/images
YourBundle/Resources/config/public/fonts
2- In some projects I use Yuicompressor for Assetic, (Yuicompressor 2.4.7 works well on windows platform) and put the yuicompressor-2.4.7.jar in:
app/Resources/java/yuicompressor-2.4.7.jar
Important: yuicompressors requires java runtime environment 1.7, as usal it is installed in the C:\Program Files (x86)\Java\jre7\bin (Win64Bits)
3- Setting the config.yml
...
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ ]
java: "C:/Program Files (x86)/Java/jre7/bin/java.exe"
filters:
cssrewrite: ~
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
yui_css:
jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
yui_js:
jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
...
4- Using the stylesheets and javascripts blocks in a templete twig
for your css files you can use:
{% stylesheets
'bundles/app/css/styles.css'
'bundles/app/css/others.css'
filter='?yui_css, cssrewrite'
output='css/common-stylesheets.css' %}
<link href="{{ asset_url }}" rel="stylesheet" />
{% endstylesheets %}
for your javascripts file you can use:
{% javascripts
'@AppBundle/Resources/public/js/myApp.js'
'@AppBundle/Resources/public/js/otherFiles.js'
filter='?yui_js'
output='js/common-javascripts.js' %}
<script src="{{ asset_url }}" type="text/javascript"></script>
{% endjavascripts %}
5- Running commands Symfony
app/console cache:clear
app/console cache:clear --env=prod
app/console assets:install web
app/console assetic:dump
app/console assetic:dump --env=prod
6- Check files created
if you go to the web folder in your symfony project, you can see the next files:
web/css/common-stylesheets.css
web/javascript/common-javascripts.js
Upvotes: 1