Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

111
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda