Move some stuff to templateParameters.php

This commit is contained in:
William 2021-09-27 09:08:36 +02:00
parent ce8952d297
commit 8af49c59d7
3 changed files with 11 additions and 9 deletions

View File

@ -1,5 +1,4 @@
<?php <?php
if(!isset($_SESSION)) session_start();
include_once("templateParameters.php"); include_once("templateParameters.php");
if ($templateParameters["render"] === FALSE) { if ($templateParameters["render"] === FALSE) {

View File

@ -1,14 +1,6 @@
<?php <?php
if(!isset($_SESSION)) session_start();
include_once("templateParameters.php"); include_once("templateParameters.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 = htmlspecialchars($templateUrlPrefix . DIRECTORY_SEPARATOR);
}
if ($templateParameters["render"] === FALSE) { if ($templateParameters["render"] === FALSE) {
return; return;
} }

View File

@ -1,4 +1,6 @@
<?php <?php
if(!isset($_SESSION)) session_start();
// Default parameter values if none is defined // Default parameter values if none is defined
$defaultTemplateParameters = [ $defaultTemplateParameters = [
"title" => "Document", // Set page title "title" => "Document", // Set page title
@ -9,3 +11,12 @@ $defaultTemplateParameters = [
foreach(array_keys($defaultTemplateParameters) as $key) { foreach(array_keys($defaultTemplateParameters) as $key) {
if (!isset($templateParameters[$key])) $templateParameters[$key] = $defaultTemplateParameters[$key]; if (!isset($templateParameters[$key])) $templateParameters[$key] = $defaultTemplateParameters[$key];
} }
// When including a 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.
if (empty($templateUrlPrefix)) {
$templateUrlPrefix = dirname(str_replace(realpath($_SERVER['DOCUMENT_ROOT']), '', realpath(__DIR__)));
if ((strlen($templateUrlPrefix) > 1)) {
$templateUrlPrefix = htmlspecialchars($templateUrlPrefix . DIRECTORY_SEPARATOR);
}
}