- This topic is empty.
June 4, 2014 at 3:44 am #171759
I am currently working in a project which have following files.
ok for example header.php is included in about.php and main.php
Header.php has got codes upto </head> Tag.
But i don’t want to to be shown in main.php.
How do i do it…
Sorry if the topic title sounds funny or wired as i could not find good one.
Any solution ?June 4, 2014 at 9:44 pm #171893
It is for jquery and it uses $(document).ready. i just want to include the that jquery file in before </head> which is on header.php by writing it in about.phpJune 5, 2014 at 12:57 am #171899
Using TheDoc’s example you can wrap your script in an if statement
// header.php <?php if(basename($_SERVER['PHP_SELF']) != 'about.php'): ?> <script src="path/to/jQuery.js"></script> <?php endif; ?> </head>
The reasoning behind placing your script tags before the closing
</body>tag is not to delay execution of the script but to avoid any delay in the rendering of your document whilst your scripts download.
This might not matter for a couple of small scripts but may delay the user from viewing your page by a couple of seconds if you have many larger scripts.
This is not always good practice though and for some scripts such as Modernizr it is better to have them placed in the
<head>as it provides you with information which may be used to affect the rendering of the rest of your page.June 6, 2014 at 5:02 am #172061
THanks but it not only about.php there are other like contact.php etc..then i should same thing again and again ??…June 6, 2014 at 6:53 am #172066
If you’re conditionally including this file then you need to decide what your conditions are.
If you want to include it only on a single page then you could use
if(basename($_SERVER['PHP_SELF']) == 'whatever.php')
else if you want to exclude it on a single page then
if(basename($_SERVER['PHP_SELF']) != 'whatever.php')
if you want to include it on a number of selected pages then I would check against an array
$pages = array('whatever.php', 'page2.php', 'somepage.php'); if(in_array(basename($_SERVER['PHP_SELF']), $pages))
This is taking place in your
header.phpfile, which I’m assuming is included at the top of each page, so you wouldn’t be repeating yourself.June 6, 2014 at 7:25 am #172067
ok man but again suppose i want to show jquery in about.php inside head tag..and i want to show modernizer js in contact.php and i want to show colorpicker.js in index.php and i want to show formvalidater.js in post.php…. Now how do i do it?June 6, 2014 at 8:57 am #172070
Well if that is the case, then using the above method, yes you would have to add a conditional statement for each of those.
I realise this is probably a hypothetical situation, but why do you want to include your scripts so selectively?
Ok But i have got such page around 50 …I use 50 conditionals that too messy….
let me explain more
for instance this is code in footer.php
<footer> </footer> ~~~~> I want to show the script #1, #2 , #3 etc.. here <~~~~ </body> </html>
this is about.php
this is index.php
i want to show this ajax-about.js and modernizer.js before the </body> tag which is located at footer.php …
Now is there any solution.?June 6, 2014 at 11:43 am #172080
Is there a reason that you can’t combine them into one file and load that on all pages?June 6, 2014 at 8:44 pm #172111
I want to show demos like color picker etc… and i want those script directly go on footer or in header..on footer it is no problem but in header i cannot figure out to show before </head> tagJune 7, 2014 at 1:25 pm #172148__Participant
If your entire header is in one file, which you simply
include, then there is no opportunity to affect its contents. Something like this might work for what you need:
<!doctype html> <html> <head> <meta charset=utf-8> <title>include with variables</title> <?= isset( $__header_js )? $__header_js: "" ?> </head>
<head>, you’d just need to do:
<?php $__header_js = '<script src="my.js"></script> <script src="my_other.js"></script>'; include "path/to/header.php";
- The forum ‘Back End’ is closed to new topics and replies.