Hi "themers"

Is it possible to identify the current "page" somehow in the page.tpl.php?
The objective is to create separated template "pages" where it will be putted different HTML, and also associate different CSS ids.

Thanks in advance,
Fernando Silva

Comments

Wesley Tanaka’s picture

I've seen $_GET['q'] used

budda’s picture

Yup, and use arg(1) arg(2) etc. to get parameters passed to the page such as node id's.

--
www.bargainspy.co.uk | More Drupal modules

iraszl’s picture

Can you post an example code as how you made it work? Thanks!

---
http://raszl.net

gerd riesselmann’s picture

Put this function somewhere, so you can access it from page.tpl.php:

function get_side_id()
{
  $ret = "page_";
  $q = arg(1);
  if ($q) {
    $ret .= $q;
  }
  else {
    $ret .= 'main';
  }
  return check_plain($ret);
}

This will return "page_main" for the front page, "page_node" for node related pages (e.g. /node/1), "page_taxonomy" for taxonomy pages etc.

You can place the returned value as id in the body tag:

<body id="<?php print get_side_id(); ?>" .... >

And write according CSS:

#page_main { background-color: white; }
#page_node { background-color: green; }
#page_taxonomy { background-color: yellow; }

arg(1), arg(2) etc contain the Drupal internal non-clean URL. for example given an URL taxonomy/term/5, arg(1) would be "taxonomy", arg(2) "term", and arg(3) "5". arg(4) will be empty.

If you want to be more specific with you pages than in my example, you may evaluate arg(2) and others also.

------------------
Gerd Riesselmann
www.gerd-riesselmann.net

iraszl’s picture

When you say: "Put this function somewhere, so you can access it from page.tpl.php" — where would that be?

---
http://raszl.net

gerd riesselmann’s picture

You can put it in a file called "template.php" within your template directory. This file will be included by phpTemplate.engine automatically if it exists.

See here: http://drupal.org/node/16383 for an example what else can be done with "template.php".

------------------
Gerd Riesselmann
www.gerd-riesselmann.net

magico’s picture

Thanks everyone!

PHPTemplate could add some of this code to make available a variable called "page_id". But for now I'll use the code in page.tpl.php

sangamreddi’s picture

Hi,

http://drupal.org/node/32077

This code will create a body class and id for every page on your site.

Sunny
www.gleez.com