To generate my pages, I use this in my index.php:
<?php
if(isset($_GET["p"]) && !empty($_GET["p"]) && in_array($_GET["p"] . ".php", scandir("views")))
{
$view = $_GET["p"];
}
else
{
header("Location: ?p=home");
}
ob_start();
require "views/$view.php";
$content = ob_get_clean();
require "views/layout.php";
?>
To generate my modal window, I add a trigger class to the link on which I want to open a modal window:
(function($)
{
$(".trigger").on("click", function(e)
{
e.preventDefault()
$(".modal, #overlay").toggleClass("show")
$(".modal .content").load("../views/sign-up.php");
})
$("#overlay").on("click", function()
{
$(".modal, #overlay").removeClass("show")
})
})(jQuery)
You can see this:
$(".modal .content").load("../views/sign-up.php");
By doing so, it works, but I would like to load the page directly dynamically, by getting the href attribute and getting the link, like this:
(function($)
{
var href = $(this).attr("href");
$(".trigger").on("click", function(e)
{
e.preventDefault()
$(".modal, #overlay").toggleClass("show")
$(".modal .content").load(href);
})
$("#overlay").on("click", function()
{
$(".modal, #overlay").removeClass("show")
})
})(jQuery)
It works, but it loads the whole template of my page.