Background: I'm currently very new to PHP and generating content dynamically, I'm using PHPStorm and using XAMPP's PHP interpreter combined with PHPStorm's built-in web server.
Problem: I've recently learnt the very handy function include()
with this I am now dynamically including my: head content, navigation and footer. This works well when I'm doing it in the index.php in the root directory, because I use relative paths for things like images in the navigation, and script paths.
But when I create a folder for a new page (directory) for example 'article' and then I create an index.php in there that uses the same include functions, the resources that were using relative paths won't be able to source their files because I am now 1 directory deep and the relative paths are specified from within the files I am including?
For example in my navigation.html I have <img alt="Logo" title="Logo" src="img/brand/Logo.png">
This will work in the root directory of the server because the path is correct but one included within documents further down in folders it will not.
Can someone explain the best practice when working with including navigation, the only thing I can think of is to duplicate the libraries I'm including and make a set with relative paths that go back +1 directories for use on the pages that have to be within folders