vincej's avatar
Level 15

Dumb Question: How Do I link to to my CSS File ?

I hate asking what appear to be dumb questions. All I want is something like "base_url" in Codeigniter so that I can create an app/assets directory and add my css, js, and images.

Stackoverflow thinks I should put it in the public directory ... don't want that. I have hunted thorugh the L4 docs at the various helpers and can't see anything that works.

Jeffrey's Larabook lesson magically has it but I could not see how he did it.

It would be great if come L5 there was a review of the docs. CI is a weak framework for sure, but their docs are outstanding.

Many thanks ! Sorry for the moan !

0 likes
10 replies
JeffreyWay's avatar

Why don't you want to put your CSS and JS in the public/ directory?

If you're using preprocessors, app/assets is fine, but then compile to public/.

Marwelln's avatar

There is no built in compiler/compressor, so if you want it inside app/assets, use Elixir or Basset. Both can compile and compress your assets to the public directory.

vincej's avatar
Level 15

Not using preprocessors - just pulling in Bootstrap css. Just want to be able to access app/assets/css like Jeffrey has have in Larabook. Then I want to be able to do something like:

echo base_url("assets/css/dashboard.css");

Something as simple as:

<link href="../../assets/css/dashboard.css" rel="stylesheet">

just gives a nastly errror.

davidxd33's avatar
Level 2

Why are you placing your CSS files in your app directory? It's meant to be in the public directory as that's what is pointed to the browser.

If your structure was

public /
  css /
     - bootstrap.css

then you can use asset('css/bootstrap.css') to generate an absolute path to the file. If you were using pre-processors, then you would want to place that in your app directory and have it compile into the public directory.

You cannot link to files inside of ~/app, the application is pointed to ~/public

1 like
vincej's avatar
Level 15

Ok - I see what you are saying. Unlike Codeigniter, the app directory is reserved for uncompiled code. Compiled code lives in the public directory. Now it makes sense.

ok, so I put my css into the public folder and then so tried

<link media="all" type="text/css" rel="stylesheet" href="{{URL::asset('public/css/bootstrap.css')}}">

as well as

{{HTML::style('public/css/bootstrap.css')}}

and both render out to the same:

http://auburntree/public/css/bootstrap.css

but both give a nasty error:

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException

As always - Many Thanks !

Andreyco's avatar

Since there is NotFoundHttpException thrown, the route is not registered. Since Laravel is trying to resolve registered route (with no luck, of course) there is no actual CSS file to load - which would be served if existed. Examine the directory strcture and make sure CSS is in right location

sitesense's avatar

I think your path is wrong, try this:

{{ URL::asset('css/bootstrap.css') }}

// or

{{ HTML::style('css/bootstrap.css') }} 

"public" is already assumed.

1 like
vincej's avatar
Level 15

SUCCESS !! Many Thanks to all of you !!

I am very grateful for all your assistance !

If there was some way of contributing to the "next gen L5" docs I would be glad to help, as I think there is a little gap here.

bashy's avatar

It's the same in any website/framework? Since your site is pointing to the public folder, only files inside that folder can be seen on the frontend (unless you do PHP includes).

Everything is relevant to /public

vincej's avatar
Level 15

Yes, looking at my Codeigniter work, indeed the css folder is outside the application folder. Perhaps looking at Jeffrey's Larabook series where he has an assets folder inside App/ threw me. Additionally there is little mention of how to exactly expose your assets in the L4 docs ... at least that's my excuse :o)

1 like

Please or to participate in this conversation.