Fix relative file paths

This commit is contained in:
Willy 2021-09-01 17:31:18 +02:00
parent 238a7576c0
commit 089591f51f
2 changed files with 18 additions and 8 deletions

View File

@ -1,6 +1,6 @@
html { html {
background-color: #fff; background-color: #fff;
background-image: url("https://willy.club/img/imagedoc-lightnoise.png"); background-image: url("../img/imagedoc-lightnoise.png");
} }
body { body {

View File

@ -1,20 +1,30 @@
<?php
// When including this template from other directories, using relative url paths is not sufficient. Therefore we use a prefix to ensure that the correct url path is given.
// Typically we put this before any local urls, such as navigation, icons etc to ensure that they use the correct path.
$templateUrlPrefix = dirname(str_replace(realpath($_SERVER['DOCUMENT_ROOT']), '', realpath(__DIR__)));
if ((strlen($templateUrlPrefix) > 1)) {
$templateUrlPrefix = $templateUrlPrefix . DIRECTORY_SEPARATOR;
}
?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php print(htmlspecialchars($templateParameters["title"])); ?> Stafett for livet</title> <title><?=htmlspecialchars($templateParameters["title"]);?> Stafett for livet</title>
<link rel="stylesheet" href="style/main.css"> <link rel="stylesheet" href="<?=$templateUrlPrefix;?>style/main.css">
<link rel="icon" href="https://kreftforeningen.no/content/uploads/2020/03/cropped-kf-propell-ikon-32x32.png" sizes="32x32"> <link rel="icon" href="<?=$templateUrlPrefix;?>img/cropped-kf-propell-ikon-32x32.png" sizes="32x32">
<body> <body>
<div class="navbar-top-head"> <div class="navbar-top-head">
<div class="navbar-top-inner"> <div class="navbar-top-inner">
<!-- Jalla løsning --> <!-- Jalla løsning -->
<a href="#" style="display: block; max-width: max-content;"> <a href="<?=$templateUrlPrefix;?>" style="display: block; max-width: max-content;">
<img style="display: block; height: 32px;" src="https://kreftforeningen.no/content/uploads/2020/03/cropped-kf-propell-ikon-32x32.png" alt=""> <img style="display: block; height: 32px;" src="<?=$templateUrlPrefix;?>img/cropped-kf-propell-ikon-32x32.png" alt="">
<div style="margin-left: 44px;"> <div style="margin-left: 44px;">
<div style="font-size: 24px; margin-top: -38px;">Stafett for livet</div> <div style="font-size: 24px; margin-top: -38px;">Stafett for livet</div>
<div style="font-size: 10px; margin-top: -6px;"><b>KREFT</b>FORENINGEN</div> <div style="font-size: 10px; margin-top: -6px;"><b>KREFT</b>FORENINGEN</div>
@ -28,8 +38,8 @@
<div> <div>
<nav> <nav>
<ul> <ul>
<li><a href="index.php">Forside</a></li> <li><a href="<?=$templateUrlPrefix;?>">Forside</a></li>
<li><a href="example.php">Eksempel</a></li> <li><a href="<?=$templateUrlPrefix;?>example.php">Eksempel</a></li>
</ul> </ul>
</nav> </nav>
</div> </div>