Jump to content


Photo

Conditions based on which html page is used...


  • Please log in to reply
5 replies to this topic

#1 mkosmosports

mkosmosports
  • Members
  • PipPipPip
  • Advanced Member
  • 196 posts

Posted 20 October 2006 - 09:41 PM

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

#2 mkosmosports

mkosmosports
  • Members
  • PipPipPip
  • Advanced Member
  • 196 posts

Posted 21 October 2006 - 11:42 PM

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?

#3 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 21 October 2006 - 11:54 PM

Have you considered using a switch statement? http://www.php.net/switch
Then 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.

#4 mkosmosports

mkosmosports
  • Members
  • PipPipPip
  • Advanced Member
  • 196 posts

Posted 22 October 2006 - 12:00 AM

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...

#5 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 22 October 2006 - 12:24 AM

Wait, just noticed something. How are you planning on passing parameters on a .html file? I didn't know that could be done.
ghome.html?group=9&season=2006
?

Anyways, if you set your url parameters to include what template is being viewed, for e.g:
template.php?template=templatename

Create your switch statement on a php file that sets your variables based on the template from the url parameters:
$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!";
}

Then include that on your template pages, or include the template page in the switch statement based on the template.

#6 mkosmosports

mkosmosports
  • Members
  • PipPipPip
  • Advanced Member
  • 196 posts

Posted 22 October 2006 - 05:21 PM

"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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users