Results 1 to 4 of 4

Thread: [RESOLVED] n00b include and echo Q

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Location
    cobwebbed to PC
    Posts
    311

    Resolved [RESOLVED] n00b include and echo Q

    Hi All

    I have recently started learning PHP in rather peicemeal fashion, trying bits on my site as i go.

    i have been using a switch loop in navigation for a while to include the page's main content. Now I want to change the heading text (that is part of the static page) to reflect teh current page content.

    Currently I have settled on using a second switch that echo's out the change dependant on th passed id (as is the other switch is also), but this is a bit heavy handed. Is there any sleeker standards compliant (accessibility v. important) method of acheiving same??

    thanks for help or pointers!
    Thanks

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: n00b include and echo Q

    to keep the basic layout of the PHP on your page, you could just have your switch at the beginning of the page, and make variables for the title and include. a quick example:

    PHP Code:
    <?php
      
    switch($_GET['page']){
        case 
    "about":
          
    $title "About Me";
          
    $include "abt.php";
          break;
        case 
    "contact":
          
    $title "Contact Me";
          
    $include "cntct.php";
          break;
        case else:
          
    $title "Home";
          
    $include "home.php";
      }
    ?>
    <h1><?php echo $title?></h1>
    <blockquote>
    <?php include($include); ?>
    </blockquote>

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: n00b include and echo Q

    When it comes to server-side code there are not really any standards to adhere to or accessibility concerns such as there are with designing content for the client side. Instead your main concern should be to achieve a functional and maintainable application design.

    kows' code is a very simple example which will work for basic sites.

    If you wanted to get more tricky you could investigate using some form of template engine to render your pages. It is easy enough to construct a simple two part template consisting of a page class which has variables such as the page title, and an accompanying template file which contains the actual HTML as well as any required PHP processing directives.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Location
    cobwebbed to PC
    Posts
    311

    Re: n00b include and echo Q

    thanks folks.
    I'll try tht method kow, I otry to write very "minimalist" code so that will prob do the trick, especially as I want to try and have the site for mobile users as well.
    thanks again
    Thanks

Posting Permissions

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



Click Here to Expand Forum to Full Width