Results 1 to 6 of 6

Thread: Reuse HTML code

  1. #1
    Join Date
    Sep 2009
    Posts
    3
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Reuse HTML code

    Hi,

    Like many others I am also reusing HTML code on several pages.
    What is most efficient way to do so?

    Thanks,

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    PHP's include if you have php set up.

    http://us2.php.net/manual/en/function.include.php

  3. The Following User Says Thank You to bluewalrus For This Useful Post:

    Shemer1 (09-08-2009)

  4. #3
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    see my post here for a nice easy "includes" tutorial link: http://www.dynamicdrive.com/forums/s...040#post202040

  5. The Following User Says Thank You to Beverleyh For This Useful Post:

    Shemer1 (09-08-2009)

  6. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    The answers above are fine. Generally you will need to use another programming language (Javascript, PHP, etc.) to filter/copy/alter your html code then output it. If you are doing a template-style webpage, as is likely, then you will be best using PHP or another server-side scripting language; in fact that's what that type of language is designed for (in addition to using databases and other nice features). Javascript can work to a limited degree (mostly for including a script in multiple pages that has some html in it), but not for a whole template-style site.
    On a bigger scale, and in some ways easier (harder to set up, but easier because you don't need to program much yourself), you can use CMS ("content management system") if you need a lot of pages with editable content and related layouts. That is the sort of system in place on most sites that have lots of similar looking pages with varied text. Basically you will use the system to set up your layout(s) (using templates) then use it to manage your content (text and other html that is put in the pages). The initial setup can be a bit of a pain, mostly just getting it to run smoothly on your server, but once that's done there's no code to mess with except the embedded html you want to output and it goes much faster than trying to do it manually. Google "CMS" to see your options. There are a lot and some are free-- one of the free ones should be fine, but there are some expensive solutions if you have the money.

    In summary, there are three levels of complexity:
    1. Basic site without much to manage: no need for any sort of content management.
    2. Some similar elements across pages, not a huge site, but getting beyond what you want to do manually: use php, etc., to make some basic included elements and maybe even use a database a bit if it gets more complex.
    3. Lots of pages, lots of changing content, and many people editing the site especially those who don't know the more complex coding languages very well: use a pre-built CMS solution.

    And of course if you want to, you could always write your own CMS, but that takes a lot of time and is only worth it if you can't find a way to use a pre-built one. CMS setups aren't actually that hard to write (just slow), and they're built around the same ideas as a basic php, etc., based system you could write yourself, just with a lot more code.
    Last edited by djr33; 09-07-2009 at 07:38 PM.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. The Following User Says Thank You to djr33 For This Useful Post:

    Shemer1 (09-08-2009)

  8. #5
    Join Date
    Sep 2009
    Posts
    3
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Many thanks to all.
    Great ideas.

  9. #6
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    I set up a CMS using a combination of a few free scripts - here's the post with all the information: http://www.dynamicdrive.com/forums/s...ad.php?t=47256
    It may or may not suit your needs but its certainly a starting point.

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
  •