mkosmosports Posted October 20, 2006 Share Posted October 20, 2006 Hey Everyone,Im trying to write a condition based on what html termplate is being used at that moment. I have 6 different templates though and I want to avoid needing to rewrite the condition six times just to accomodate these six html templates. Here is an example of code for one of the conditions... if ($groupid == "9" || $groupid == "11") { echo("<div style=\"background: #70A2D7 url(images/pastyears.jpg) no-repeat top\"> <form name=\"CommonDrop\"> <select name=\"DropSelect\" onchange=\"go()\" style=\"font-size: 14px; margin-top: 30px\"> <option selected value=\"#\">--Select--</option> <option value=\"ghome.html?group=9&season=2006\">2006</option> <option value=\"ghome.html?group=11&season=2002\">2002</option> </select> </form> </div>");}Now, I want the same condition for when the user visits "teams.html" as opposed to "ghome.html" but I dont want to have to rewrite the above condition again to just replace the html template name. Is there some way I can use a variable there which would define the html template that the user is currently visiting, such as <option value=\"$currenthtml?group=9&season=2006\">...but what would that variable have to be defined as?Any help is much appreciated...mkosmosports Quote Link to comment Share on other sites More sharing options...
mkosmosports Posted October 21, 2006 Author Share Posted October 21, 2006 Hmm...no answer in a couple of days... :-\..maybe Ive confused everyone with the question. Does anyone understand what Im trying achieve and does it sound at all possible? Quote Link to comment Share on other sites More sharing options...
hostfreak Posted October 21, 2006 Share Posted October 21, 2006 Have you considered using a switch statement? http://www.php.net/switchThen set your variables based on the page. You could set the url parameters to let you know what page they are using. Then just use the $_GET global. Quote Link to comment Share on other sites More sharing options...
mkosmosports Posted October 22, 2006 Author Share Posted October 22, 2006 Ive been looking into it yes. But the thing thats been perplexing me though is how to be able to pull the name of the html template which is currently being looked at using some kind of a function maybe. If I was able to do that the rest would be simple... Quote Link to comment Share on other sites More sharing options...
hostfreak Posted October 22, 2006 Share Posted October 22, 2006 Wait, just noticed something. How are you planning on passing parameters on a .html file? I didn't know that could be done.[code]ghome.html?group=9&season=2006[/code]?Anyways, if you set your url parameters to include what template is being viewed, for e.g:[code]template.php?template=templatename[/code]Create your switch statement on a php file that sets your variables based on the template from the url parameters:[code]$templates = array ( 'template_one', 'template_two',);$template = $_GET['template'];if (in_array($template, $templates)){ switch ($template) { case"template_one": $blah = blah; break; case"template_two": $blah = blah; break; }}else{ echo "Error: That template doesn't exist!";}[/code]Then include that on your template pages, or include the template page in the switch statement based on the template. Quote Link to comment Share on other sites More sharing options...
mkosmosports Posted October 22, 2006 Author Share Posted October 22, 2006 "Wait, just noticed something. How are you planning on passing parameters on a .html file? I didn't know that could be done."All my templates are html files and passing parameters work flawlessly. I always thought it didnt matter whether the extension is .php or .html....I see your solution to my problem though, using a template variable, this sound like what I need to do. Thanks hostfreak. I will try this as soon as I get home again later today....mkosmosports Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.