hi,
I am trying to switch templates for different parts of my site. I put this in my template.php:

function _phptemplate_variables($hook, $vars = array()) {
  switch ($hook) {
    case 'page':
      if (arg(0)=="alias" && arg(1)=="myAlias"){
          $vars['template_file'] = 'mypagetemplate';
      }
      break;
  }
  return $vars;
}

That works fine - if my URL is "www.drupalsite.com/alias/myAlias". But I want to go with "www.drupalsite.com/myAlias". So I changed the above lines to:

      if (arg(0)=="myAlias"){
          $vars['template_file'] = 'mypagetemplate';
      }

But this doesn't work. What have I to change? Or is there another way to do this?

thanks
orbi

Comments

nevets’s picture

Using arg(n) returns the un-aliased parts of the path so you would want to look for the unaliased version of the name

orbi’s picture

hi, I don't understand this. When I look for

      if (arg(0)=="alias" && arg(1)=="myAlias"){

then it works with "www.drupalsite.com/alias/myAlias". But "myAlias" is an alias also ...!
Is there no way to skip the "alias" part?

thanks
orbi

shanghaiguide’s picture

Seems like we're both trying to do the same thing ;)

I solved it by grabbing

$_REQUEST['q']

This returns the actual url after the http://www.somedomain.com/

eg

If its http://www.somedomain.com/country
$_REQUEST['q'] = country

If you have multiple url pieces - eg
http://www.somedomain.com/country/city

You can use explode

eg

$mypath = explode("/", $_REQUEST['q']);

$mypath[0] contains country
$mypath[1] contains city...

I'm using this and a custom page.tpl.php with a switch statement based on the path to make customized pages based on the menu path..
Each of my template pages has a bunch of php code to pull in queries and stuff populated from other nodes.

Hope that helps.

Of course, after the lightbulb went off in my head, I tried searching for explode and $_request, and found this node which says pretty much the same thing. Grrr :)

http://drupal.org/node/55433

Cheers,

Lawrence.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=
http://www.shanghaiguide.com

orbi’s picture

Nice - I was close to giving up ;)

I will try it - thanks a lot!

g
orbi