dcsimg
www.webdeveloper.com
Results 1 to 9 of 9

Thread: Buttons and page redirection

  1. #1
    Join Date
    Jan 2011
    Posts
    5

    Buttons and page redirection

    Hi
    I've taught myself some web dev and thought of a question re buttons.
    When I'm doing my buttons, i'm linking to another html page. So this means for every page I have a separate html page (Which I'd expect) but it means on every page I have to write all the html for things that are identical on every page, such as background, buttons, layout formatting etc etc.

    Is this the norm or is there a better way, like is it possible to make templates where you only have to replace the things you actually want to change but don't have to rewrite (well ok, copy and paste) all the html code every time i want a new page.

    It would seem to me and my limited knowledge that I will have to keep all the code in every page (unless I use JS or frames but i dont really want to) but I was thinking, if a company has a massive website surely they dont have loads of html files that all contain code for the borders/buttons etc etc or do they?

    Cheers

  2. #2
    Join Date
    Aug 2009
    Posts
    593
    Easiest way to do it would be to piece your pages together from a webserver.
    Do you know any server side languages, such as PHP?

  3. #3
    Join Date
    Jan 2011
    Posts
    5
    Quote Originally Posted by thraddash View Post
    Easiest way to do it would be to piece your pages together from a webserver.
    Do you know any server side languages, such as PHP?
    I dont actually, but I'm a programmer (not done web before though) so I'm sure i could learn without too much trouble. how would it work in php then? I'm obviously not looking for a php lesson, or any code, but just an explanation of how you use it to build ur pages.

    How are websites usually put together; with server-side code?

  4. #4
    Join Date
    Aug 2009
    Posts
    593
    I can't think of a better way than to use a server language.

    As a basic template example:

    header.php
    HTML Code:
    <div style="border: solid 1px black;">HEADER</div>
    navigation.php
    HTML Code:
    <a href="#">Link 1</a>
    <a href="#">Link 2</a>
    <a href="#">Link 3</a>
    footer.php
    HTML Code:
    <div style="border: solid 1px black;">FOOTER</div>
    Then just add them to a page (this is the really simple version btw)...

    home.php
    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    	<head>
    		<title>Home</title>
    		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    	</head>
    	<body>
    
    <?php require(header.php); ?>
    <?php require(navigation.php); ?>
    
    		PAGE SPECIFIC CONTENT
    
    <?php require(footer.php); ?>
    
    	</body>
    </html>

  5. #5
    Join Date
    Jan 2011
    Posts
    5
    Ah very good. I'd tried doing something similar with html files actually. Worked but couldnt quite get formatting right.

    What's the differences in the many server-side languages then; why use php over, say, asp?

    I appreciate your help!

  6. #6
    Join Date
    Aug 2009
    Posts
    593
    There is actually a website called that describing what you've just asked :P

    http://www.aspvsphp.com/

    You can't be good at everything, I just so happened to learn PHP and it has done all that I could ask for.

    Good luck making your choice.

  7. #7
    Join Date
    Jan 2011
    Posts
    5
    ah cheers for that. So PHP is more flexible with databases and server compatibility, is like C++ (which I have coded in), is faster and allows me to use free tools and servers?

    Sounds like a no brainer to me. Thanks for all your advice!

  8. #8
    Join Date
    Dec 2010
    Posts
    32
    I am new at this malarky too and have been experimenting with server side html includes. (No need for php or asp etc.)

    You simply create one file with the content to be duplicated elsewhere and call it what you like.

    Then in your html doc you put the following in where you would like the included segment to be inserted:-

    <!--#include file="filename.html" -->

    You save this file as whatever.html or .shtml (apparently the latter is preferred by some servers, although I don't know why).

    The resulting page in the browser looks like a fully formed page.

    You can have many includes in one document and, if you wanted to, you could make a template containing all of the includes for future use.

    I heard, somehwere along on the line, that using includes speeds up page loading, as the included data is cached.

  9. #9
    Join Date
    Jan 2011
    Posts
    5
    Cheers for that tip. Tried that myself but the formatting never came out 100% perfect. Done it the PHP way n it's all dandy

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles