Using CSS in Laravel views?
Using CSS in Laravel views?
I've just began learning Laravel, and can do the basics of a controller and routing.
My OS is Mac OS X Lion, and it's on a MAMP server.
My code from routes.php:
Route::get('/', function() { return View::make('home.index'); }); Route::get('businesses', function() { return View::make('businesses.index'); }); Route::get('testing', function() { return View::make('testing.index'); }); Route::get('hello', function() { return "Hello world!
"; });
That works, the views display perfectly, ''however'' what I want to try and do is include CSS within the views, I tried adding in a link to a stylesheet within the directory but the page displayed it as the default browser font even though the css was in the HTML!
This is index.php from businesses within the views folder:
Business is a varied term. My content here.
I tried using the Blade template engine in my other views folder (testing) to display CSS but again the CSS did not show despite it being in the testing folder!
How can I overcome this problem, and get better - as I'm slowly learning this framework.
Answer by andrekeller for Using CSS in Laravel views?
your css file belongs into the public folder or a subfolder of it.
f.e if you put your css in
public/css/common.css
you would use
HTML::style('css/common.css');
In your blade view...
Or you could also use the Asset class http://laravel.com/docs/views/assets...
Answer by Diego Casta?o for Using CSS in Laravel views?
You can also write a simple link tag as you normaly would and then on the href attr use:
of course you need to put your css file under public/css
Answer by montogeek for Using CSS in Laravel views?
Put your assets in the public folder
public/css public/images public/fonts public/js
And them called it using Laravel
{{ HTML::script('js/scrollTo.js'); }} {{ HTML::style('css/css.css'); }}
Answer by Bryan Posas for Using CSS in Laravel views?
That is not possible bro, Laravel assumes everything is in public folder.
So my suggestion is:
- Go to the public folder.
- Create a folder, preferably named css.
- Create the folder for the respective views to make things organized.
- Put the respective css inside of those folders, that would be easier for you.
Or
If you really insist to put css inside of views folder, you could try creating Symlink (you're mac so it's ok, but for windows, this will only work for Vista, Server 2008 or greater) from your css folder directory to the public folder and you can use {{HTML::style('your_view_folder/myStyle.css')}}
inside of your view files, here's a code for your convenience, in the code you posted, put these before the return View::make()
:
$css_file = 'myStyle.css'; $folder_name = 'your_view_folder'; $view_path = app_path() . '/views/' . $folder_name . '/' . $css_file; $public_css_path = public_path() . '/' . $folder_name; if(file_exists($public_css_path)) exec('rm -rf ' . $public_css_path); exec('mkdir ' . $public_css_path); exec('ln -s ' . $view_path .' ' . $public_css_path . '/' . $css_file);
If you really want to try doing your idea, try this:
But it won't work even if the file directory is correct because Laravel won't do that for security purposes, Laravel loves you that much.
Answer by Mahendra Jella for Using CSS in Laravel views?
Put your assets in the public folder
public/css public/images public/fonts public/js
And then called it using Laravel
{{ URL::asset('js/scrollTo.js'); }} // Generates the path to public directory public/js/scrollTo.js {{ URL::asset('css/css.css'); }} // Generates the path to public directory public/css/css.css
(OR)
{{ HTML::script('js/scrollTo.js'); }} // Generates the path to public directory public/js/scrollTo.js {{ HTML::style('css/css.css'); }} // Generates the path to public directory public/css/css.css
Answer by Ahmad Sharif for Using CSS in Laravel views?
We can do this by the following way.
{{ HTML::style('css/style.css', array('media' => 'print')) }}
It will search the style file in the public folder of Laravel and then will render it.
Answer by huuthang for Using CSS in Laravel views?
put your css File in public folder . (public/css/bootstrap-responsive.css) and
Answer by Akshay Khale for Using CSS in Laravel views?
Copy the css or js file that you want to include, to public folder or you may want to store those in public/css or public/js folders.
Eg. you are using style.css file from css folder in public directory then you can use
But in Laravel 5.2 you will have to use
and if you want to include javascript files from public/js folder, it's fairly simple too
and in Laravel 5.2 you wll have to use
the function url()
is a laravel helper function which will generate fully qualified URL to given path.
Answer by Sambhav for Using CSS in Laravel views?
Like Ahmad Sharif mentioned, you can link stylesheet over http
but if you are using https
then the request will be blocked and a mixed content error will come, to use it over https use secure_asset
like
https://laravel.com/docs/5.1/helpers#method-secure-asset
Answer by Bono for Using CSS in Laravel views?
Since Laravel 5 the HTML
class is not included by default anymore.
If you're using Form or HTML helpers, you will see an error stating class 'Form' not found or class 'Html' not found. The Form and HTML helpers have been deprecated in Laravel 5.0; however, there are community-driven replacements such as those maintained by the Laravel Collective.
You can make use of the following line to include your CSS or JS files:
Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72
0 comments:
Post a Comment