Jump to content

How can i load Multiple CSS/JavaScript files in PHP?


WhiteRau

Recommended Posts

hello!

 

in my header.php file i have the following line of code:

<link rel="stylesheet" href="<?php echo $pageCSS; ?>">

 

in the document proper, i have the following at the top of the page:

<?php $pageCSS="_css/compare.css"; ?>

 

this works as expected and it's clean and neat.  what i want to know is how i can adapt this to pass MULTIPLE  JavaScript files through it.  would it be best to pass an array of files and then step through the array?  would be nice to be able to pass a simple comma-delimited list.  any help would be appreciated.

 

WR!

There are many possibilities, one of which is:

 

Defining the CSS files:

<?php
$css_files = array(
  "_css/compare.css",
  "_css/groovy.css",
);
?>

And then when you are producing the HTML output:

<?php foreach ($css_files as $cf) {
  print "<link rel=\"stylesheet\" href=\"$cf\">\n";
} ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.