Вопрос

I've tried searching for this but couldn't find an exact response for my particular issue.

So I've made a friend a website and I am quite enjoying it - it has about 10 HTML files, 1 css, and 1 js file. The biggest irritation I've come across is this:

If I make one minor tweak to, let's say... the header... I have to do it among all html files, and it's quite annoying. I use one CSS file for the stylings, so it's just a matter of pasting on the html code 10 times.

I don't really know PHP, but I think it has a function to do something like this, but i don't want the index to be www.mywebsite.com/index.php (I want it to remain mywebsite.com - i.e. not showing index.html because of its name).

So that raises the question, is it possible to join the html constituents, like:

header.html body.html footer.html

in to one bigger file containing all three, with no special trickery, just copying the contents of each line by line? If so, can I do it without php? If so, or if not, could anyone please tell me how, and if there are any issues with this kind of approach let me know?

Thanks!

Это было полезно?

Решение 2

You should use php for including all your headers,footers etc. You can use it even if you do not have any knowledge about php. Follow the link here -> http://www.w3schools.com/php/php_includes.asp . The includes are server-side. When the user requests for your website, php copies all your includes and pastes it to the main-file and then sends data to the user.

For example

//the php file
<?php
 include "header.html";
 include "footer.html";
?>

The header.html file =>

<div class="header">...</div>

The footer.html file =>

<div class="footer">...</div>

The output =>

<div class="header">...</div>
<div class="footer">...</div>

Другие советы

If your webserver supports it, you can use server-side includes. Apache supports it but the Includes option must be set (Options +Includes in .htaccess).

<!--#include file="footer.html" -->

This would be the easiest way I can think to do this without scripting something using CGI, PHP, ASP, etc.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top