Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

110
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda