cusejuice
cusejuice

Reputation: 10681

PHP Include Absolute/Relative Paths CSS

My PHP files within folders are not rendering my default CSS files.

I have a "document-head.php" file that contains:

<link type="text/css" rel="stylesheet" href="assets/css/main.css"/>

Within each file I include this 'document-head.php';

For example, the directory I have is:

index.php
|__ assets
    |__ css
        |__ main.css
|__ includes

    |__ document-head.php

|__ components
    |__ secondary.php

|__ partials

Within "components/secondary.php" contains

 <?php include('../_includes/document_head.php'); ?>

And within "index.php" contains:

<?php include('_includes/document_head.php'); ?>

How do I make sure that files within folders that include this "document_head.php" always render CSS/JS files?

Edit: The reason I can't use absolute URL's is that one of the developers configured a script that allows me to upload my application to an FTP where I can name a new folder. For example, if all my files are in "secret-app", in the terminal I can publish my app to an FTP with the new folder "test-app" and it will create "mydomain.com/test-app/secret-app". (It's a ghetto system, but it's useful for my particular needs.)

Upvotes: 0

Views: 1200

Answers (2)

Jairo Malanay
Jairo Malanay

Reputation: 1347

if this stylesheet is within the document_head.php

<link type="text/css" rel="stylesheet" href="assets/css/main.css"/>

then try this :

<link type="text/css" rel="stylesheet" href="../assets/css/main.css"/>

sorry for my grammar :D

Upvotes: 0

Ignacio Ocampo
Ignacio Ocampo

Reputation: 2713

Try change to an absolute href url like:

<link type="text/css" rel="stylesheet" href="/yourApp/assets/css/main.css"/>

If you're using a framework, you will have several ways to get your base_url.

Upvotes: 1

Related Questions