Skip to content

Instantly share code, notes, and snippets.

@ano
Created April 12, 2023 16:49
Show Gist options
  • Save ano/e9e9dacb216adbd4488c92c9c7af8790 to your computer and use it in GitHub Desktop.
Save ano/e9e9dacb216adbd4488c92c9c7af8790 to your computer and use it in GitHub Desktop.
PHPMAKER load your own css and js based on the page name

In PHPMaker you can use the following code in Page_Head or Page_Foot to load your own custom scripts:

$page = basename($_SERVER['PHP_SELF']);

if (file_exists("../my/code/$page.php")) { AddStylesheet("../my/code/$page.php"); // Add PHP script }

if (file_exists("../my/code/$page.css")) { AddStylesheet("../my/code/$page.css"); // Add CSS stylesheet }

if (file_exists("../my/code/$page.js")) { AddClientScript("../my/code/$page.js"); // Add JavaScript }

In the above code, we use "../my/code/" as the base path for the CSS and JavaScript files. We then check if the files "../my/code/$page.css" and "../my/code/$page.js" exist using the file_exists() function. If they do, we add the CSS and JavaScript files using the AddStylesheet() and AddClientScript() functions respectively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment