FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » including CSS & JS on only pages that need that CSS & JS
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: including CSS & JS on only pages that need that CSS & JS [message #175576 is a reply to message #175565] Sun, 09 October 2011 20:31 Go to previous messageGo to previous message
Michael Joel is currently offline  Michael Joel
Messages: 42
Registered: October 2011
Karma:
Member
On Sat, 8 Oct 2011 23:51:10 -0700 (PDT), paris2venice
<paris2venice(at)gmail(dot)com> wrote:

> I'm still a newbie at PHP. What would be the right way to include CSS
> and Javascript such that I could add CSS and JS just for those pages
> that need it?
>
> Would it be something like this? Is this how you do it?
>
> <?
> php require_once './css.php'; /* css.php contains
> doctype, meta & css needed universally */
> ?>
>
> <!-- link href= calls to CSS needed on local page only -->
>
> <?
> php require_once './js.php'; /* js.php contains
> javascript calls needed universally */
> ?>
>
> <!-- script type="text/javascript" calls to Javascript needed on
> local page only -->
> </head>
>
>
> Thanks a bunch for your help.


I think you are meaning you want to use PHP includes to drop in your
css and javascript. You can use the normal method combines with PHP or
just PHP...

Combined methode:

<link rel="stylesheet" type="text/css" href="GlobalCSS.css" />
<script type="text/javascript" src="GlobalJavascript.js"></script>
<?php

if($MYpageID="THIS IS THE PAGE I WANT IT ON") {
include("StylesForThisSpecialPage.php");
include("StylesForThisSpecialPage.php");
}
?>

The other method:

<?php
include("GlobalCSS.php");
include("Globalavascript.php");

if($MYpageID="THIS IS THE PAGE I WANT IT ON") {
include("StylesForThisSpecialPage.php");
include("SpecialJavascript.php");
}
?>

Of course the PHP files must be written just as they would be if they
were coded directly on the HTML page (not as if they are being
"linked").
Right or wrong? It works.

Mike
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: .htaccess vs PHP header(location:)
Next Topic: How to redirect user based on user country?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 16:06:37 GMT 2024

Total time taken to generate the page: 0.03847 seconds