Have an include() for specific content with PHP -


i have several files header , footer, let's file1.php, file2.php , file3.php

these files include() files header.php , footer.php.

now concern this... each page has load general header content css styles, -specific- style such page. happens on footer: loads bunch of scripts pages, specific script specific page.

how can achieve this? don't want put specific script on specific page because might not attached one, several ones, js script or css style can attached 5 or ten pages...

i thinking switch() each case in header or footer page, conditional (such $_server['php_self']) in other pages, how can include thing? include() i'm looking for?

thank you.

this pretty beyond scope of stackoverflow why not.


switch inside template

i see added thinking of using switch. here example of simple do.

header.php

<html> <head>    <title>...</title>    <?php switch(basename($_server["script_filename"], '.php')) {    case 'file1': ?>        <script src="file1.js"></script>    <?php break;    case 'file2': ?>        <script src="file2.js"></script>    <?php break;    }    ?> </head> <body> 

just sample code in-between case , break. code initiates switch on file name, file1.php 'file1'.


output buffering

what else output buffering. let's have template @ file1.tpl.php, have header.php. inside file1.php, this:

ob_start(); include "file1.tpl.php"; $content = ob_get_clean(); include "header.php"; 

everything processed file1.tpl.php stored in $content. inside header.php, load $content see fit:

<html><head><?= $content ?></head><body> 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -