HTML Template File

前端 未结 6 647
梦毁少年i
梦毁少年i 2021-01-28 04:29

I know this is a beginner\'s question, but I\'ve been searching online and all I can find are \"free website templates\" that I can download.

The question is: How can I

相关标签:
6条回答
  • 2021-01-28 04:54

    There are two places you can do this:

    1. Server side programming at runtime (which allows for quick updates to templates but needs server support)
    2. Something at build time (which simplifies cache control and doesn't require anything to run on the server)

    The two basic approaches to this are includes (simple) and full template systems (powerful).

    For a runtime include system, the popular choice is PHP's include function. An alternative is SSI. You can even use a C preprocessor.

    Template systems include PHP's Smarty.

    My weapon of choice is Template-Toolkit, which can be used via Perl at runtime and comes with ttree for use at build time.

    Less sane options involving making the client do it and include frames and JavaScript.

    0 讨论(0)
  • 2021-01-28 04:58

    This kind of behaviour can only (sensibly) be achieved through the use of sevrer side languages like php or asp.

    Non-sensible ways of handling this would include iframes blech or framesets double-blech.

    0 讨论(0)
  • 2021-01-28 05:01

    For plain HTML you just use include:

    <!--#include FILE="menu.inc" -->
    
    0 讨论(0)
  • 2021-01-28 05:05

    Typically a server-side scripting language such as PHP is used to dynamically include such files. Client-side solutions usually involve iframes, etc. which is usually not preferred.

    0 讨论(0)
  • 2021-01-28 05:07

    You are describing server side includes.

    Server Side Includes are useful for including a common piece of code throughout a site, such as a page header, a page footer and a navigation menu.

    Example of usage:

    <!--#include virtual="../quote.txt" -->
    

    This will add the text of quote.txt to the page - if you add it to multiple pages, you can make your change in this one file and it will show on all pages in was included in.

    Different web servers have different support and additional features for these, so you need to check the documentation for yours.


    Many websites that need dynamic features (like fetching data from a database) will use some kind of server side scripting language for this kind of functionality - examples include PHP, Perl, ASP.NET, JSP and many more.

    0 讨论(0)
  • 2021-01-28 05:09

    There are a few ways you can do this, but first of all we must establish what hosting environment you'll be running your site on. It's also completely dependant on what you're trying to achieve - are you programming, or just simply including a HTML page in another HTML page?

    If your web-host allows you to run back-end code like Classic ASP, ASP.NET, PHP, MVC, Ruby or Perl, then each one has one or more methods to include files.

    It's possible (though I haven't used this for a long, long time) that you can use an SSI directive within your HTML file. This is usually web-server dependant, rather than language dependant, and you can read more about it here. It's the easiest way to include files, but it has a lot of limitations.

    Alternatively, you could use AJAX to retrieve a page from your server and update the HTML in your page dynamically. Remember though, that this relies on the user having JavaScript enabled, and requires a bit more effort on your side.

    0 讨论(0)
提交回复
热议问题