How to link css file inside bundle - Symfony 2.8 - twig

I generated new bundle and I have styles.css file in following pathsrc/AdminBundle/Resource/public/styles.css. In my base.html.twig file I have link (templates/head.html.twig)
<link href="{{ asset('bundles/adminbundle/css/styles.css') }}" rel="stylesheet" type="text/css" />
But this giving error not found file. Please help.

Files from src/AdminBundle/Resource/public/styles.css are not copied automaticlly to web/bundles
You need to to run command
php app/console assets:install

Related

Django not loading style file from static directry

I am facing a strange issue with the Django application on my local, the file is available in the static directory.
The following is in the settings.py
STATIC_ROOT = SITE_ROOT + '/static/'
STATIC_URL = '/static/'
this is how I am trying to include style file
<link href="/static/msc.css?v=1.2" rel="stylesheet" type="text/css" />
the following is added in urls.py
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns += staticfiles_urlpatterns()
The file exist in the static directory, but it is not loading, I am facing a 404 error in console for the URL: http://localhost:8000/static/msc.css?v=1.2
please help me in this regard thanks.
You are not doing things the Django way.
When working with static files in Django
a) you need to use {% load static %} at the very beginning of your template
b) The link to static file is created using the following pattern
<link href="{% static 'path/to/style.css' %}" rel="stylesheet" type="text/css" />
Suppose that I have a directory in my django project static/css/style.css, then
<link href="{% static 'css/style.css' %}" rel="stylesheet" type="text/css" />

Bundle with both CDN and local Resources in CSS

bundles.Add(new StyleBundle("~/Resources/styles/css").Include(
"~/Resources/styles/bootstrap-3.1.1.css",
"~/Resources/third-party/ng-table.css",
"~/Resources/styles/site.css"));
I have above kind of bundle in my 'BundleConfig.cs' file.How can I add cdn into above bundle ? Any help would be highly appreciated.
My CDN is :
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet" />

LESS, Dotless and Visualstudio

I started today with LESS. It looks awesome to work with and I will need it on my internship soon.
My less code:
#color: #4D926F;
body {
background-color: #color;
}
Not anything special.
My html:
<!Doctype HTML>
<html>
<head>
<title>#ViewBag.Title</title>
<link href="#Url.Content("~/Content/style.less")" type="stylesheet" rel="stylesheet/less" />
<script src="#Url.Content("~/Scripts/less-1.4.1.min.js")" type="text/javascript"></script>
</head>
<body>
#RenderBody()
</body>
</html>
The Less script file is downloaded from http://lesscss.org/
My file structure:
The result:
FileError: 'http://localhost:58123/Content/style.less' wasn't found (404)
in style.less
Index
When I install dotless via Package Manager everything works perfect.
My question is what do I need to runn it without Dotles? I dont have problems installing Dotless or using it. I just want to know whats the missing link why the LESS gives that error. Why do I get a 404 error when the file is there?
Dotless compiles the .less to .css. So you would need to add a reference to the resulting .css that Dotless compiles. Also you would want to remove this line from your code.
<link href="#Url.Content("~/Content/style.less")" type="stylesheet" rel="stylesheet/less" />

In JSF a file name with style.css is not supported, why?

When I was linking the Css file using the following tagline
<h:outputStylesheet library="css" name="style.css" target="body"/>
and I have the arranged directory structure as WebContent->resources->css->style.css
and I was getting result code on browser as <link type="text/css" rel="stylesheet" href="RES_NOT_FOUND" />
But when I have changed the file name to styles.css, it worked but I didn't get the reason that what was the problem with style.css.
The problem is how you have set your resource files inside your project. Since this looks to be your actual folder structure:
resources
- css
- style.css
You have to call your CSS file like this:
<h:outputStylesheet name="css/style.css" />
More info:
What is the JSF resource library for and how should it be used?

Assetic not generating any files

I am using Assetic with Twig but not the symfony2 framework.
Here's how the project is set up
/site
/template
/css
/public_html
/css
The raw css is stored under /site/template/css and I want assetic to minify the css and output it to /public_html/css.
Here's how assetic is set up as a twig extension
$factory = new AssetFactory(//absolute path to `/site/template/`);
$factory->setDefaultOutput(//absolute path to `/public_html/`);
$factory->setDebug(false);
$twig->addExtension(new AsseticExtension($factory));
Then in my template:
{% stylesheets 'css/screen.css' output='css/*' %}
<link href="{{ asset_url }}" type="text/css" rel="stylesheet" />
{% endstylesheets %}
I can see that assetic has generated a unique url in the final output:
<link href="css/00da241.css" type="text/css" rel="stylesheet" />
However, if I look in /public_html/css, the files are never generated!
I am using a Windows 7 server with apache and PHP has no issues writing files anywhere.
What could be causing this?
What you've done here is asking assetic to generate URL's to assets (using twig).
But assets urls don't point to any file yet. You still have to generate them, using a dump script:
<?php
use Assetic\AssetWriter;
use Assetic\Extension\Twig\TwigFormulaLoader;
use Assetic\Extension\Twig\TwigResource;
use Assetic\Factory\LazyAssetManager;
$am = new LazyAssetManager($factory);
// enable loading assets from twig templates
$am->setLoader('twig', new TwigFormulaLoader($twig));
// loop through all your templates
foreach ($templates as $template) {
$resource = new TwigResource($twigLoader, $template);
$am->addResource($resource, 'twig');
}
$writer = new AssetWriter('/path/to/web');
$writer->writeManagerAssets($am);
This script uses twig templates to define which files to dump.
You will have to define the $templates variable and the $twig variables of course.

Resources