Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    May 2013
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Repeat HTML code in multiple pages (js/angular)

    Sup people.
    I'm making the visual part of my web application, all developed in javascript with the support of bootstrap and angularjs.
    I was not so sure about where to post this thread, but considering it regards the visual style of my application, here I am.

    The "site" contains fixed stuff, like a complex navigation bar, that is composed by lot of lines of code, that got repeated in each page.

    I'd obviously like to avoid code repetitions, both for ease of change (if i'd like to change a voice in my navbar i should change it in all the pages, argh!), so i was thinking to use something to memorize my code and repeat it while loading the page.

    My choice would be absolutely javascript, no php and if possible no jquery.

    I don't really know how to do it, i should declare a function that, if called, loads my snippet but i really don't know how this should be handled!

    Thank you very much

  • #2
    Regular Coder Donkey's Avatar
    Join Date
    Sep 2003
    Location
    Blackfield UK
    Posts
    312
    Thanks
    1
    Thanked 36 Times in 36 Posts
    You need to use Sever Side Includes.
    http://httpd.apache.org/docs/current/howto/ssi.html
    " 90% of everything is crud" - Theodore Sturgeon
    Filthy Beast - a 60's Rock Band

  • #3
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,307
    Thanks
    23
    Thanked 612 Times in 611 Posts
    @ Mr. Key as a long time Theodore Sturgeon fan I believe the quote should be '90% of everything is crap'. and I think this is a derived quote.

    @yourveins
    My choice would be absolutely javascript, no php and if possible no jquery.
    sorry I like to do things the easy way [php].

    Remove the repetitious coding and save it as a separate file. Make your main file a .php instead of a .html.
    Then where the menu code should appear place this code there:
    Code:
    <?php include_once("the_menu_file_name.php"); ?>
    You should also include your header or the entire top of your page, if it's the same on all page.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #4
    Regular Coder Donkey's Avatar
    Join Date
    Sep 2003
    Location
    Blackfield UK
    Posts
    312
    Thanks
    1
    Thanked 36 Times in 36 Posts
    Quote Originally Posted by sunfighter View Post
    @ Mr. Key as a long time Theodore Sturgeon fan I believe the quote should be '90% of everything is crap'. and I think this is a derived quote.
    That's how I originally remembered it but when I tried to check it online I could only find the sanitised version, so I thought that I (as the politicans say) "misremembered" it. Is there a way to check? I hate to be inaccurate.
    " 90% of everything is crud" - Theodore Sturgeon
    Filthy Beast - a 60's Rock Band

  • #5
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,307
    Thanks
    23
    Thanked 612 Times in 611 Posts
    If you can't find it with google then I'm at a loss. I'm just going from memory and that might be wrong.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."


  •  

    Posting Permissions

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