|
-
Dec 30th, 2008, 09:39 AM
#1
Thread Starter
Hyperactive Member
[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 
-
Dec 30th, 2008, 04:42 PM
#2
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>
-
Dec 30th, 2008, 08:30 PM
#3
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.
-
Jan 8th, 2009, 10:18 AM
#4
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|