I'm quite new to php, I'm currently attempting to use it to determine what content should be loaded. It's working perfectly but I'm just wondering if there are any downsides I may run into or is what I'm doing considered bad practice? Because it feels very wrong.
This is what I'm doing:
<body>
<?php
$req = "templates" . $_SERVER['REQUEST_URI'] . "_layout.php";
if (file_exists($req)) {
include("templates" . $_SERVER['REQUEST_URI'] . "_layout.php");
}
else {
include("templates/errors/404.php");
}
?>
</body>
I have a templates folder, in which there are a bunch of different files like home_template.php, about_template.php etc., This way when someone navigates to website.com/home - the home_template.php will be loaded into the body section. (The landing page is "_layout.php", so it will load on the index page.)