How can I install assets in web/css/ folder - symfony

I have installed Symfony 2.8 and I have put header.css in web/css, but I don't know how can I access it.
The web browser returns the following error:
GET http://www.grupoinversores.com/css/header.css 404 (Not Found)

You need symlink. For example... here you js, css, img directories:
AppBundle/Resources/public/
In console command $ php app/console assets:install --symlink creates symlink for this js, css, img directories for AppBundle/Resources/public/.
Now you js, css, img here: web/bundles/app/css, web/bundles/app/js, web/bundles/app/img and for currect generate path use this:
<link rel="stylesheet" href="{{ asset('bundles/app/css/style.css') }}">
http://symfony.com/blog/new-in-symfony-2-6-smarter-assets-install-command

it seems based on live page as I looked there you have created a "header.css" directory not a file. No 404, though.

Do you use Twig? Can you post the part of your HTML that tries to call your header.css file?
If you are using Twig, have you tried something like:
<link href="{{ asset('cms-assets/css/bootstrap/bootstrap.css') }}" rel="stylesheet" />
inside your HTML?
In my case the bootstrap.css file is inside the folder:
/web/cms-assets/css/bootstrap
And as seen, I can access it using the "asset" with Twig

Related

Where can I add assets in symfony 5?

I'm using symfony 5 and I have no idea where can I pu my css, js, images files.
I read many posts about it but none helped me...
I tried:
composer require symfony/asset
symfony console assets:install
Here is the way i am using asset function in my twig files:
<link rel="stylesheet" type="text/css" href="{{ asset('css/base.css') }}">
And yes I have a file at public/css/base.css...
But when I inspect the result page, my line is replaced by:
<link rel="stylesheet" type="text/css" href="/css/base.css">
Did someone have any idea ?
Best regards,
If you're NOT using webpack (or webpack encore), your assets should be in your public folder which is the root of your public project. For example, if you have a file called style.css in public/css/style.css, you can access it in your browser with the url (assuming you use a local server started in the public dir) http://localhost:8000/css/style.css.
The Symfony asset component goal is to guess if your project is in a subdirectory and therefore to resolve the correct path. In order to use it in a Twig template with the previous imaginary file :
<link rel="stylesheet" href="{{ asset('css/style.css') }}">
The asset function will be able to produce the right path for your file.
If you're using webpack, the setup is a bit harder so if you don't I won't explain it here.

CSS file not loading Laravel Localhost

I am trying to load CSS file in localhost but it's just showing white page. I was try to drag and drop file direct to browser and its opened. So file its not empty. and file also open when i use a server and add link to file.
I am using laravel 5.8, PHP 7.2
<link href="{{ URL::asset('css/style.css') }}" rel="stylesheet" type="text/css" media="all" />
CSS file location /public/css i am getting link in source http://localhost/css/style.css
This is most likely a file reference error. Check the markup output and compare the file URL against where it actually sits in the directory structure. If they match up, maybe a directory permissions issue?
In css links only asset is working fine... No need to include URL. so try using only asset.

Symfony 2.7 + Sass + Assetic: Styles not applied/visible when using app_dev.php

I would like to use Sass based styles in my Symfony 2.7 WebApp. So far I have used Compass to compile Sass files (located not in the web/ dir but within the Bundles) to CSS files. This works fine, but on a new server Ruby is not available and thus Compass is not an option anymore.
Following the Symfony Docu, I have added leafo/scssphp to the project and activated in the config file:
# app/config/config.yml
assetic:
filters:
scssphp:
formatter: 'Leafo\ScssPhp\Formatter\Compressed'
# ...
The Sass files within the Twig templates:
{% stylesheets
'MyMainBundle/Resources/styles/sass/header.scss'
filter="scssphp"
output="css/header.css" %}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
This works fine when using Symfony in non-dev mode:
php app/console assetic:dump --env=prod --no-debug
The file web/css/header.css is created and everything works without any problem. However, when using the app_dev.php front controller, no styles from header.scss are applied. Only styles from other files which are linked directly (without using Assetic) are rendered.
This strange, because when I inspect the generated/loaded HTML file, the style sheet seems to be included correctly:
<link rel="stylesheet" href="/app_dev.php/css/header_header_1.css" />
Calling /app_dev.php/css/header_header_1.css directly shows the style sheet with all its styles.
So all styles seem to be in place. Everything as it should be. Except, that no styles are being rendered.
Do you have any idea how to solve this?
I managed to solve the problem: The css file was transferred with Content-Type: text/htmlinstead of text/css. This was caused by the format_listener settings of the FOSRestBundle. Adding css to the accept rules solved this. The css files are now transferred as text/css and everything works fine.

get css in the folders using assetic

I would like to know if it is possible with symfony 2 and Assetics to say that I want to load all of the css files in a specific folder even though this one has some other folders inside.
For example I have :
css/aaa.css
css/bbb.css
css/jquery/ccc.css
css/jquery/ddd.css
in assetics I would do that to load :
{% stylesheets 'bundles/my-bundle/css/*' %}
<link rel="stylesheet" href="{{ asset_url }}" media="screen" />
{% endstylesheets %}
this will only load aaa.css and bbb.css
Is there a way to say : 'take everything' in one single line (sure i could add each folder in the stylesheets tag but I want to know if I can avoid doing that)
Thank you
You can't do this thing directly with assetic as is yet but it's possible thanks to everzet and his AsseticPipeline class suite and will probably be brought in next Assetic major version.
So what to do now ?
test previous KnpRadBundle version by cloning it here
get more information about how to implement it in your project : read this discussion
Good luck.
In the app_dev environment, the files are processed for each request, and run through all the filters before they are provided by the Assetic controller. This is useful, because we will see every change directly:
In a production environment, this process is just too slow. In this case, Assetic is able to generate real files, which are static and can be delivered statically:
To generate the final assets, invoke the following script in your console:
$ php app/console assetic:dump --env=prod --no-debug
All the css will combine in the production environment.The above command will generate a css folder and a combined file into that folder.

Symfony 2 - having troubles with asset function

I'm having troubles with calling stylesheets and javascript via asset() function..
my app is running on dev enviorment so the url is - dproc.local/app_dev.php/
The base.css is in /src/Dproc/Resources/views/Dproc/css/base.css
<link href="{{ asset('/css/base.css') }}" type="text/css" rel="stylesheet" />
Doesnt work.
How should my link have to be? I didnt understood how asset() function works..
Thanks
You need to run the command
asset install --web
so that the asset files are copied to web folder.

Resources