It would really be better to use a template file loading the content through parameters in the URL, but if you are used to this structure, and/or prefer the URL to stick to the file names simply, follow a small example:
php contact.
<html>
<head>
<title>Demo</title>
</head>
<body>
<?php
include('menu.php');
?>
<div class="conteudo">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eget varius urna. Quisque convallis augue quis magna consequat eleifend. Nulla posuere sit amet lectus sed porta. Ut quis mauris luctus, lobortis ligula et, interdum massa. Praesent varius tempor laoreet. Vestibulum vulputate massa vel nunc vulputate, ut pellentesque massa rutrum. Aenean posuere, arcu eget eleifend auctor, diam lorem volutpat massa, vel commodo quam urna a mauris.
</div>
</body>
</html>
php menu.
<?php
$pagina_atual = basename($_SERVER['PHP_SELF']);
if ($pagina_atual == 'contato.php') {
echo '<script src="js/contato.js"></script>';
}
?>
<ul id="menu" class="clearfix">
<li<?php echo ($pagina_atual == 'index.php' ? ' class="ativo"' : ''); ?>>
<a href="index.php">Início</a>
</li>
<li<?php echo ($pagina_atual == 'sobre.php' ? ' class="ativo"' : ''); ?>>
<a href="sobre.php">Sobre</a>
</li>
<li<?php echo ($pagina_atual == 'contato.php' ? ' class="ativo"' : ''); ?>>
<a href="contato.php">Contato</a>
</li>
</ul>
as you can see, only when the page is php contact. is going to include the <script src="js/contato.js"></script>
and bonus was an example of how to apply the active class in the menu.
You don’t quite understand the problem. You want a page that receives data via include? Do you have a "mom" page where you want to include one of the 10 files according to some condition? What changes on different page is the style or structure of HTML? You intend to provide some sort of identifier to know which of the 10 pages is on?
– Blau
Get the part that interests you from the PHP URL, and make the condition with it
– Enoque Duarte
@Enoqueduarte then, you would have some example of how to create this condition?
– Felipe Viero Goulart
<?php if (basename($_SERVER['PHP_SELF']) == "pagespread") { print "my html"; } ?>
– Enoque Duarte
@Felipestoker, explaining my question better to give you a suitable example: why make 9+1 pages that call the same layout, if you can make one with such a layout and change only the data that will go in it? If there are 10 pages, there would be no reason to do 10 includes, just copy the layout for each one and that’s it.
– Blau