Jump to content

Passing of title info from include file


kurt.santo

Recommended Posts

I generate my nav bar in main.php as "<?php include('globalNav.htm');?>" where globalNav.htm consists of a list with all relevant links with relevant title/value pairs.In main.php I generate the title as <?php echo $_GET['title']; ?>, but found that this does not work (assume this is because title is generated before the nav info is pulled in). How else would you achieve what I am after?Also, in context of include files: I pull in the main content via <?php include('pageContent.htm');?>. Is there a way to automate which file is pulled in from title information? Nav bar comes before the page content in code, so this should be possible, shouldn't it?What is your advice with error management? How would I generate my own error messages if sth goes wrong?I know it is a lot of questions. Just thought as they relate I might as well put them in one thread...Kurt

Link to comment
Share on other sites

I generate my nav bar in main.php as "<?php include('globalNav.htm');?>" where globalNav.htm consists of a list with all relevant links with relevant title/value pairs.In main.php I generate the title as <?php echo $_GET['title']; ?>, but found that this does not work (assume this is because title is generated before the nav info is pulled in). How else would you achieve what I am after?
You're not sending the title by GET, but through a $variable in the same page.
Also, in context of include files: I pull in the main content via <?php include('pageContent.htm');?>. Is there a way to automate which file is pulled in from title information? Nav bar comes before the page content in code, so this should be possible, shouldn't it?
Put 'pageContent.htm' (or only part of it, to be pieced together in the call to include) in $variable and call <?php include($variable); ?>. Here is my attempt at a coded answer to these questions. (All includes are require_once'd because I think the whole page is necessary - and necessarily once; change them as desired.)includer.php
<?php	require_once 'included.php';	$content = 'content.php';?><html>	<head>		<title><?php echo $title; ?></title>	</head><?php	require_once $content;?></html>

included.php

<?php	$title = 'Your Title';?>

content.php

	<body>		Your content.	</body>

What is your advice with error management? How would I generate my own error messages if sth goes wrong?
You might be able to submit the errors to a database; I'm working on some AJAX to do this with JavaScript. I believe PHP has a setting to suppress errors for deployment.
Link to comment
Share on other sites

You might be able to submit the errors to a database; I'm working on some AJAX to do this with JavaScript. I believe PHP has a setting to suppress errors for deployment.
http://ca.php.net/manual/en/function.error-reporting.phpSet a switch to one error reporting level while testing/building and another while live. http://ca.php.net/manual/en/function.error-log.phpAnd same with the Logging of errors.
Link to comment
Share on other sites

http://ca.php.net/manual/en/function.error-reporting.phpSet a switch to one error reporting level while testing/building and another while live. http://ca.php.net/manual/en/function.error-log.phpAnd same with the Logging of errors.
Thanks for both inputs. Use now variables at top of page, which makes it really easy to change different files as you just have to go into top of file. Am a bit lost in understanding how included.php can make my title assignement easier... I created 10 includes files for the different pages of my site. Would I need to create 10 diff included files? Sure I got this wrong as I might then as well just write a "normal" HTML title...Will look in more detail into the given links, cheers...Kurt
Link to comment
Share on other sites

Thanks for both inputs. Use now variables at top of page, which makes it really easy to change different files as you just have to go into top of file. Am a bit lost in understanding how included.php can make my title assignement easier... I created 10 includes files for the different pages of my site. Would I need to create 10 diff included files? Sure I got this wrong as I might then as well just write a "normal" HTML title...
The $_SERVER['SCRIPT_NAME'] variable has the value of the current page's name (filename, not title).
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...