tl;dr at the bottom I want to set directories for Assetic files (css, js, images, whatever) to:
/web/assets/{css,js,images}/
That would be the main directory, used in my ::base.html.twig
file.
Also, I will use /web/assets/bootstrap/{css,js,images}/
to handle bootstrap files, this is actually working, I'm using braincrafted/bootstrap-bundle
and it has an output: bootstrap
parameter, which is good.
And then, I'm using SonataAdminBundle
with custom templates, I want theese templates assets to be stored into /web/assets/admin/{css,js,images}/
This is my config.yml file
framework:
#esi: ~
translator: ~
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
packages:
assetic:
base_urls: '/assets'
admin:
base_urls: '/assets/admin'
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ "WebDificilBundle"]
#java: /usr/bin/java
#read_from: %kernel.root_dir%/Resources/views/
write_to: %kernel.root_dir%/../web/assets/
filters:
cssrewrite: ~
less:
node: /usr/local/bin/node
node_paths: [/usr/local/lib/node_modules]
apply_to: "\.less$"
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
braincrafted_bootstrap:
less_filter: less
output_dir: bootstrap
assets_dir: %kernel.root_dir%/../vendor/twbs/bootstrap
jquery_path: %kernel.root_dir%/../vendor/jquery/jquery/jquery-1.10.2.js
auto_configure:
assetic: true
twig: true
knp_menu: true
knp_paginator: true
customize:
variables_file: %kernel.root_dir%/../vendor/twbs/bootstrap/less/variables.less
bootstrap_output: %kernel.root_dir%/Resources/less/bootstrap.less
bootstrap_template: BraincraftedBootstrapBundle:Bootstrap:bootstrap.less.twig
And this is what I have, for example in ::base.html.twig
{% block stylesheets %}
<!-- Bootstrap -->
<link href="{{ asset('assets/bootstrap/css/bootstrap.css') }}" rel="stylesheet" media="screen">
{% stylesheets filter='cssrewrite' package='assetic' 'css/style.css' %}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
{% endblock %}
{% block javascripts %}
<script src="https://code.jquery.com/jquery.js"></script>
<!-- Include all JavaScripts, compiled by Assetic -->
<script src="{{ asset('assets/bootstrap/js/bootstrap.js') }}"></script>
<script type="text/javascript">
<!--
window.base_url = '{{ path('decision') }}';
//-->
</script>
{% include 'BraincraftedBootstrapBundle::ie8-support.html.twig' %}
{% endblock javascripts %}
This is /web
folder by default
robhunter@debianmoi:~/public_html/dificildecision/web$ ls -atls
total 52K
4,0K drwxr-xr-x 3 robhunter robhunter 4,0K ene 9 14:41 ./
4,0K drwxr-xr-x 9 robhunter robhunter 4,0K ene 9 14:14 ../
4,0K -rw-r--r-- 1 robhunter robhunter 2,6K ene 9 12:11 .htaccess
8,0K -rw-r--r-- 1 robhunter robhunter 5,7K ene 9 10:07 config.php
4,0K drwxr-xr-x 2 robhunter robhunter 4,0K dic 28 01:46 fonts/
4,0K -rw-r--r-- 1 robhunter robhunter 1,2K dic 26 22:29 app_dev.php
12K -rw-r--r-- 1 robhunter robhunter 11K dic 26 22:29 apple-touch-icon.png
4,0K -rw-r--r-- 1 robhunter robhunter 960 dic 26 22:29 app.php
4,0K -rw-r--r-- 1 robhunter robhunter 1,2K dic 26 22:29 favicon.ico
4,0K -rw-r--r-- 1 robhunter robhunter 106 dic 26 22:29 robots.txt
Then I run this commands php app/console cache:clear --env=prod --no-debug | php app/console assets:install | php app/console assetic:dump
php app/console cache:clear --env=prod --no-debug | php app/console assets:install | php app/console assetic:dump
And I've got this output
Dumping all dev assets.
Debug mode is on.
14:43:42 [dir+] /home/robhunter/public_html/dificildecision/app/../web/assets/bootstrap/css
14:43:42 [file+] /home/robhunter/public_html/dificildecision/app/../web/assets/bootstrap/css/bootstrap.css
14:43:43 [file+] /home/robhunter/public_html/dificildecision/app/../web/assets/bootstrap/css/bootstrap_bootstrap_1.css
14:43:44 [file+] /home/robhunter/public_html/dificildecision/app/../web/assets/bootstrap/css/bootstrap_form_2.css
14:43:45 [dir+] /home/robhunter/public_html/dificildecision/app/../web/assets/bootstrap/js
14:43:45 [file+] /home/robhunter/public_html/dificildecision/app/../web/assets/bootstrap/js/bootstrap.js
14:43:45 [file+] /home/robhunter/public_html/dificildecision/app/../web/assets/bootstrap/js/bootstrap_transition_1.js
14:43:45 [file+] /home/robhunter/public_html/dificildecision/app/../web/assets/bootstrap/js/bootstrap_alert_2.js
14:43:45 [file+] /home/robhunter/public_html/dificildecision/app/../web/assets/bootstrap/js/bootstrap_button_3.js
14:43:45 [file+] /home/robhunter/public_html/dificildecision/app/../web/assets/bootstrap/js/bootstrap_carousel_4.js
14:43:45 [file+] /home/robhunter/public_html/dificildecision/app/../web/assets/bootstrap/js/bootstrap_collapse_5.js
14:43:45 [file+] /home/robhunter/public_html/dificildecision/app/../web/assets/bootstrap/js/bootstrap_dropdown_6.js
14:43:45 [file+] /home/robhunter/public_html/dificildecision/app/../web/assets/bootstrap/js/bootstrap_modal_7.js
14:43:45 [file+] /home/robhunter/public_html/dificildecision/app/../web/assets/bootstrap/js/bootstrap_tooltip_8.js
14:43:45 [file+] /home/robhunter/public_html/dificildecision/app/../web/assets/bootstrap/js/bootstrap_popover_9.js
14:43:45 [file+] /home/robhunter/public_html/dificildecision/app/../web/assets/bootstrap/js/bootstrap_scrollspy_10.js
14:43:45 [file+] /home/robhunter/public_html/dificildecision/app/../web/assets/bootstrap/js/bootstrap_tab_11.js
14:43:45 [file+] /home/robhunter/public_html/dificildecision/app/../web/assets/bootstrap/js/bootstrap_affix_12.js
14:43:45 [file+] /home/robhunter/public_html/dificildecision/app/../web/assets/bootstrap/js/bootstrap_bc-bootstrap-collection_13.js
14:43:45 [file+] /home/robhunter/public_html/dificildecision/app/../web/assets/bootstrap/js/jquery.js
14:43:45 [file+] /home/robhunter/public_html/dificildecision/app/../web/assets/bootstrap/js/jquery_jquery-1.10.2_1.js
14:43:45 [dir+] /home/robhunter/public_html/dificildecision/app/../web/assets/js
14:43:45 [file+] /home/robhunter/public_html/dificildecision/app/../web/assets/js/71cfa0b.js
14:43:45 [file+] /home/robhunter/public_html/dificildecision/app/../web/assets/js/71cfa0b_dificildecision_1.js
14:43:45 [file+] /home/robhunter/public_html/dificildecision/app/../web/assets/js/71cfa0b_core_2.js
14:43:45 [dir+] /home/robhunter/public_html/dificildecision/app/../web/assets/css
14:43:45 [file+] /home/robhunter/public_html/dificildecision/app/../web/assets/css/64661ba.css
[RuntimeException]
The source file "/home/robhunter/public_html/dificildecision/app/../web/css/style.css" does not exist.
assetic:dump [--watch] [--force] [--period="..."] [write_to]
Why is Symfony2 throwing this error? It creates bootstrap stuff correctly, it creates /web/assets{css,js,images} | /web/bundles | /web/assets/bootstrap/{css,js,images}/
/web/assets{css,js,images} | /web/bundles | /web/assets/bootstrap/{css,js,images}/
/web/assets{css,js,images} | /web/bundles | /web/assets/bootstrap/{css,js,images}/
so it's ok (actualy, not the /web/assets/admin/
because I'm not using thoose twig files right now, but, there are no style.css
file which is the main one, and it is defined in my ::base.html.twig
file inside stylesheets brakets...
tl;dr I need to know how to set correctly the assetic configuration in config.yml file, and also how to set things in twig files, to have everything working inside folders I want to, and, of course, when users go to prod env, if they see the source I don't want to see whatever.com/bundles/mybundle/css/foo.css
I want just whatever.com/assets/foo.css
{% stylesheets filter='cssrewrite' package='assetic' **'css/style.css'** %}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
With this directive you say to dump all css in a style.css file in css folder
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.