Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4 background-image: url

I am trying to get the full path of my image to work across the board instead of using image/blah/blah on my page I have them working with the blade template engine

 {{ HTML::style('css/bootstrap.css'); }}
 {{ HTML::style('css/bootstrap-responsive.css'); }} 
 {{ HTML::style('css/style.css'); }}
 {{ HTML::script('js/jquery.js'); }}

But I am trying to use background-image for a menu bar

background-image: url(images/transparentBackground.png)

Is there a way to use Blade templates to get that image to load the full path?

If I use

background-image: url({{ HTML::script('images/transparentBackground.png'); }})

It doesnt work and returns errors.

like image 866
Lynx Avatar asked Jun 08 '13 03:06

Lynx


3 Answers

Well, first of all, you'd want to use

url({{ URL::asset('images/transparentBackground.jpg') }})

instead of

`HTML::script()`.

That would work if you are using inline styles.

If you are trying to have blade parse a linked stylesheet however, that's just never going to work. Nor should it. In that case, you might want to look into using something like Sass and Compass. With the right configuration, you can have full paths to your images generated automatically.

like image 133
Rogier Avatar answered Nov 02 '22 23:11

Rogier


I don't understand your problem very well. Why do you need a full path? This is css. Images folder has to be near a css file.

In your case try background-image: url(../images/transparentBackground.png)

-- public (folder)
---- css/style.css
---- images/transparentBackground.png 
like image 20
spezia Avatar answered Nov 03 '22 01:11

spezia


You can use helper functions Here

Here is an example of background-image using helper function

background-image: url("{{ public_path('images/bg_invoice.jpg') }}");

public_path is a helper function to the path of public folder in your Laravel app and images is the nested folder in public. Thanks

like image 37
Hussnain sheikh Avatar answered Nov 02 '22 23:11

Hussnain sheikh