Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

109
Views
Load Javascript and CSS files depending on the page in PHP

I am creating a web-based application in PHP. I have separated headers and footers and have created separate files for them "headers.php" && "footers.php". The "headers.php" file has all the styles in it and also the CSS files of different libraries and the same goes with the "footers.php" file, it has all the scripts in it.

My question is, is there a way where I can include all these different CSS and scripts depending upon the template.

here is an example:

if(template == 'somefilename.php'){
    <script type="text/javascript" src="js/libraries/dataTables.bootstrap4.min.js"></script>
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If I understand your question correct, you could do the following:

In the file, lets say home.php in that file you include or require your header.php and footer.php

// home.php
<?php
$addToHeader = '<script type="text/javascript" src="js/libraries/dataTables.bootstrap4.min.js"></script>';

require 'header.php';

// your html content

require footer.php;
?>

// header.php

// Your header code with your links etc...
<?php
if (isset($addToHeader)) {// Check if $addToHeader exist to prevent undefined errors
  echo $addToHeader;
}

By doing something like this you can inject different links/scripts into your pages. The same can be done within your footer but then with an other variable name.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!