SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Oct 2005
    Posts
    285
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Repeated blocks throughout site

    I've been working so much with cms like wordpress lately that it's been ages since I built a HTML/CSS site from scratch.

    My mindset is creating sites based on themes and templates. What is best practice these days to repeat sections of sites across pages without repeating code? Should I use php includes? Any clever way to do this now?

  2. #2
    SitePoint Wizard webcosmo's Avatar
    Join Date
    Oct 2007
    Location
    Boston, MA
    Posts
    1,429
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    most modern web technology works with code reuse.
    include is one of the choice with php.

    with asp .net you can build master page template and reuse it for different pages.

  3. #3
    Mouse catcher silver trophy
    Stevie D's Avatar
    Join Date
    Mar 2006
    Location
    Yorkshire, UK
    Posts
    5,820
    Mentioned
    110 Post(s)
    Tagged
    1 Thread(s)
    The easiest way is to use server-side includes. Wherever you want to pull in a repeated code block, just add the line
    Code:
    <!--#include virtual="../block1.htm" -->
    and then save the appropriate fragment file as "block1.htm". You can include as many different blocks as you want in any one page, but they do all have to be on the same domain.

    You will need to either save your main files with a .shtml extension, or configure the server to treat all files as though they are .shtml.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •