CSS doesn't load on one of my route/view - php

I have a sub-view that extend my master-view, and for some reasons all my css doesn't seem to load only on that page. I extend them as usual like I normally do.
view show.blade.php
#extends('layouts.internal.master')
#section('content')
TESTING ...
#stop
I notice, it only break on that route : /account/112
Any hints / suggestion on this will be much appreciated !

Without seeing your file paths or how you are loading your CSS, it's very difficult for us to say but it sounds like your file paths are wrong.
There is a difference between these two:
<link rel="stylesheet" href="css/app.css">
<link rel="stylesheet" href="/css/app.css">
Note the forward slash.
The first one is relative to your current path. So, for example, if you're currently at http://localhost:8000/account/112, the first one is like saying http://localhost:8000/account/css/app.css, which is most likely unwanted behavior. The second one is relative to the root directory so it will always be http://localhost:8000/css/app.css, which is probably what you want to do.
Laravel also comes with helpers function like asset so if you decide to use that and do something like this:
<link rel="stylesheet" href="{{ asset('css/app.css') }}">
It will generate an absolute URL / full path from your root URL. So, it'll generate something like this:
<link rel="stylesheet" href="http://localhost:8000/css/app.css">

/account and /account/112 can not access same path in same way. Like if /account access a image like 'images/img/img.jpg' , /account/112 need to access it like '../images/img/img.jpg'. Its all about folder structure. Now for your problem you need to use asset like below (laravel 5 specific)
// if you have save css file at as root/public/css/main.css
{!! HTML::style('css/app.css') !!}
remember to add to composer.json
"illuminate/html": "5.*"
And to aliases
'Form' => Illuminate\Html\FormFacade::class,
'HTML' => Illuminate\Html\HtmlFacade::class
Point to be noted:
{{asset('css/some.css')}}
this is for laravel4. you wont get it working in laravel 5.

Related

Why won't this PHP code feed in to the link TAG href attribute? (local host, not using laravel)

Disclaimer: I haven't got a clue what I'm doing with PHP I'm just playing around with it.
I have my css file in a folder named CSS and then my header.php and footer.php in the main site folder. If i include the header.php in other directories I am just using:
<?php include('../header.php'); ?>
I know this isn't the way to do it however I don't know how to configure it probably (with a config.php file etc..) but my issue is, once the header's included in files in any directory of course it will look for the css/main.css file in that folder so I've tried doing the following:
<link rel="stylesheet" href="<?php echo $_SERVER['DOCUMENT_ROOT']. '/JAGS/css/main.css' ?>" />
When I use the php line in the body it displays the path
E:/xampp/htdocs/JAGS/css/main.css
but if I use it there in the link tag then doesn't work.
What seems to be my problem other than the fact I'm clueless with PHP. Is there something else I should be using? Is there something I need to do in my xampp config files?
Edit: By "doesn't work" I mean the styles are not being applied.
Edit 2: Inspecting shows the following:
<link rel="stylesheet" href="E:/xamppp/htdocs/JAGS/css/main.css">
I know there's an extra p on the end of xampp, this is actually what I have the folder named. Is it because it's not saying "localhost/JAGS/CSS/main.css"? If so what would be the reason for this?
Edit 3: Console shows error below:
Not allowed to load local resource: file:///E:/xamppp/htdocs/JAGS/css/main.css
Edit 4: Not using Laravel
Thank you
Why do you require the document root, you should just place a dot in front of it and set the base url in a meta tag.
<base href="yourdomain.com">
<link rel="stylesheet" href="./JAGS/css/main.css'/>

how to setup the assets folder in CodeIgniter like in Laravel

like the public folder given by laravel default i tried to create something like that for easy make up of my css, js, picture and so on. I tried configuring it like this. In my application/helpers/utility_helpers.php
<?php
function asset_url()
{
return base_url().'assets/';
}
?>
I have my assests folder along with application, system, user_guide etc.
i confugured the autoload function of application/config as :
$autoload['helper'] = array('url','utility');
when i hit any url in browser now, it says
An Error Was Encountered
Unable to load the requested file: helpers/utility_helper.php
how can i make it and can you explain me if i need to specify root for that helpers also.And if not can i simply access the assets like this:
<img src="assets/base_components/build/banner.png">
in my view
In fact the answer is very simple, you only need to put ../ before every file that is under assets folder, because the root of the codeigniter is in application folder, but how you can't put the assets folder there and for the best practices, let the structure of the project like below and apply this solution to the path of the files:
Website Folder structure
|---|application\
|-------(CodeIgniter application folders...)
|---|assets\
|-------css\
|-------images\
|-------js\
|-------robots.txt
|---|system
|-----(CodeIgniter system folder...)
|index.php
Path of the files
ex.:
CSS
<link href="../assets/css/bootstrap.min.css" rel="stylesheet">
<link href="../assets/css/plugins/font-awesome.css" rel="stylesheet">
IMAGES and others
<img src="../assets/images/build/banner.png">
JAVASCRIPT
<script src="../assets/js/jquery-2.1.4.js"></script>
<script src="../assets/js/plugins/jquery.scrollSpeed.js"></script>
Note.:
Always remember to applay the best practices to the code too (this will help for the performance of the the page too), like below:
<html>
<head>
meta tags
favicons
css files styles
</head>
<body>
page structure code
javascript files
</body>
</html>
Yo can do this instead:
<img src="<?= base_url('assets/base_components/build/banner.png') ?>">
Your code looks ok, it should work.
According to the error
Unable to load the requested file: helpers/utility_helper.php
there is no utility_helper.php file in application/helpers/ folder. Check if the file exists in that folder or if you don't have a typo in the file name.

Symfony3 bad routing for css

Prehistory:
I've created CRUD for entity, and now trying to apply my styles to that CRUD's pages.
My problem looks like:
As you see css-files are loading from "/mannapp/vdservers", but they should be loaded from "/".
What should I do?
Routing for this page:
manapp_vdservers_index:
path: /manapp/vdservers/
defaults: { _controller:MainBundle:VDServers:index }
methods: [GET]
Links for assets looks like this:
<link href="css/general.css" rel="stylesheet">
Actually all of my routes with level more than 1 works bad:
/page - css will be loaded well
/page/page1 - css will be loaded from /page/css
Your path in href is relative (it doesn't start with /). This means that css/general.css is added to the current URI (not the location of the template). So when visiting a page on URI /something/foo, the stylesheet is loaded from /something/css/general.css.
What you need is an absolute path: /css/general.css.
To fix things even more, you can use Symfony's asset() helper function. This function expects one argument, which is a path relative to the web/ directory of your application.
So change your line to either <link href="/css/general.css" rel="stylesheet"> or <link href="{{ asset('css/general.css') }}" rel="stylesheet"> (recommend).

Laravel 5 Views Structure

I added a bootstrap template to laravel 5 Resources directory.
And added only the index.php to views in Resources.
The index.php file is pointing the files like :
<link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
And its not loading.
In my routes.php i am loading :
Route::get('/', function () {
return view('index');
});
As I can see in the code, ViewFinder does a case sensitive search for a template based on whatever you provide to the view() helper.
Pass Index to view() instead of index or change the template name from Index.php to index.php.
If your view renders correctly, but CSS file is not loaded, it means it's inaccessible to the browser. Files that are not returned via Laravel need to end up somewhere in /public folder so that web server can read them and return to the browser. You need to place them there manually or using some build toos (gulp, grunt, ...).
In your case, your bootstrap file must end up in public/bootstrap/css/ folder.
You could also fetch the bootstrap file from a CDN by using one of absolute URLs you can find here: http://www.bootstrapcdn.com/, e.g.:
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
Add bootstrap files inside the public folder. Suppose your bootstrap file inside the laravel\public\css then:
{!! Html::style('css/style.css') !!}
and jquery files laravel\public\js
{!! Html::script('js/jquery.js') !!}

How to add a web font using the asset-pipeline?

I would like to add google web font using asset-pipeline. I know how to add fonts via files, but I don't know how to add something like this
<link href='http://fonts.googleapis.com/css?family=Lato:300,400,700' rel='stylesheet' type='text/css'>
via asset-pipeline. I have only found tutorials for adding static fonts via files.
Does anyone know what should I do?
Typically you would want to add this to a master.blade.php (something all blade templates will extend)
Asset::add('google-font', 'http://fonts.googleapis.com/css?family=Lato:300,400,700');
Reference Laravel Forum
there is the simple way to do it
{{ HTML::style('http://fonts.googleapis.com/css?family=Playfair+Display') }}

Categories