Forum Moderators: coopster
<a href="data/template.php?id=file1">file1</a>
<a href="data/template.php?id=file2">file2</a>
etc..
Where 'file1' and 'file2' are the first files in the subdirectory it generated the link for (file1.php and file2.php). These are just examples, and I am also using mod_rewrite, but I am showing this for simplicity.
As you can see, it simply loads template.php, and includes the text found in file1.php. The template.php file also uses the name of the variable passed to it, to generate the page title, and the page headers.
But often I need to have punctuation in the page title and headers, and of course I cannot use question marks etc. in the file name.
I know I could do something like this in the file1.php:
<?php $page_title = "whatever";?> But of course these variables can't be used by template.php because they would of been needed before the content file is included.
I hope I am explaining this well :) So you may see what I am getting at.. And I am also not using databases for the moment, so this is not an option either.
I am just trying to figure out the best way to pass variables from the file1.php into template.php before the location in the file where it is being included, while still keeping this type of method. This method allows me to simply add a new file into the directory, and the links will automatically exist, etc.
Any thoughts? Thanks!
Typically you get stuck with included files when they combine both data and code execution - that is information, but they also do something. If they're files that do something, like output stuff (yours is doing that by all the non-php stuff), they of course need to be included at exactly the right place where that stuff needs to be done or outputted. This can be a pain, like in your case where you need the info first.
The thing to do then is to convert all the stuff your include file does into information of some kind. You can do this by either setting variables - which have your page contents, which you just output later - or if you need to do fancy stuff, you can set functions, and later call those functions. Thing is, though, you can't set a function with the same name twice. So when you're including files with functions, use include_once, just in case some sloppy piece of code later tries to include the same file again.
Happy coding.
You mentioned using both a variable for content, and a function to display the content.
If I make the included content one big variable, it seems like it would be too big. I am not sure if there would be any problems with that. I will have to look up the limitations, etc.
The functions idea sounds very nice. I will probably try that. Since the only function will need to be the actual 'content' of the included file, I see no reason why I would need to call it up more than once in the same instance of the template file, so that may be best.
Thanks again! I will let you know how it works for me.
I really tried to search around for this info, but it is one of those things that can be tricky to search for it seems :) Maybe it's just me!
We will see!
i have like i said tried several instances, and i know mod_write is working, thats not the issue, i actually had the server looking for index.html, and that confused me got the 404 not found, so whats the next step? sorry for the long post, but getting kinda desparate.
thank you guys
dosdawgs