Possible to have “inheritance” in html?

后端 未结 2 1666
故里飘歌
故里飘歌 2020-12-22 03:53

Let\'s say all of my html pages will have a top bar and banner with the same content. Rather than copy the code for these content on all html pages, is it possible to have

2条回答
  •  清酒与你
    2020-12-22 04:38

    In this situations (as far as I know)

    1. You can use template based editors like Dreamweaver
    2. You can use framesets (don't use them)
    3. You can use iframe (meh.)
    4. You can convert your files to PHP and just use a single include command (Y)
    5. Copy and paste whole thing and when you get 100 pages, try to add a new menu...

    I'd like to see other solutions too.

    Example:

    Lets say I've created a template.html it's something like

    
       
        asd
        style tags keywords bla bla bla 
       
    
       
       
    unique content here

    Allright this is my one html file. Lets take top section of the page. Menu will be same but content will be changed so this is top of the page:

    
       
        asd
        style tags keywords bla bla bla 
       
    
       
    

    Save this part as top.php Now let's see what have we left:

    unique content here

    This will be our post page. But how can we get codes from top.php? Just like that:

    
    
    unique content here

    Now, save this as page1.php BINGO! You did not wrote anthing about menu but include method will bring it for you.

    Include basically writes everything from a file to another. You can check differences for include_once, require, require_once too.

    Allright, we've created our first page. What about second one? Exactly the same:

    
    
    my second page here

    Save this as page2.php

    Well, you need to change your menu now but there are two pages, two hundred pages, two million pages... Who cares. Just change top.php that's all.

    Please note that in this codes; top.php, page1.php and page2.php are in SAME directory. If you want to include from another path, you must use for example:

    
    //OR
    
    

    depending on your path.

    I hope this helps. Read PHP guides for include. It's really easy.

    You need a testing server (or you can use a local server like WAMP, XAMP etc.) to execute PHP files.

提交回复
热议问题