Jump to content

Archived

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

mkosmosports

Conditions based on which html page is used...

Recommended Posts

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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
"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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.