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!

Link to comment
Share on other sites

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";
} ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.