Hi,

Is it possible to detect which page is currently being displayed in Drupal. For example, if I have aliased a URL to ?q=events, is there any variable that is passed through to the template that will allow me to extract 'events' ? Reason is that I then want to use the name to apply as a class name to the body tag. For example"


<?php $page = //get the page name (e.g. 'events') somehow here ?>

<body class="<?php echo $page ?>">

etc

would give:


<body class="events">

Thanks,

Nick

Comments

lyricnz’s picture

You can access the elements in the URL using arg(0), arg(1), etc. See http://api.drupal.org/api/function/arg/5

You should be VERY careful about using URL arguments directly in the page like this - you may leave yourself open to security issues when bad URLs are submitted to your site. Yes, this happens all the time to production sites.

nroper’s picture

Hi,

Thanks for this. Only problem is that it doesn't return info from the alias.

Nick

zeta ζ’s picture

You don’t want to use the path, because that will mean the same page is displayed differently depending on whether the alias is used.

You need to detect if an alias exists for that page: This is more like the functionality provided by taxonomy.
___________________
It’s in the detaιls…

demonstration portfolio

zeta ζ’s picture

You can also make more extensive changes to your page by copying page.tpl.php to page-events.tpl.php in your theme.
See: http://drupal.org/node/104316

This would be equivalent to checking that 'events' had been entered – anything else would not use this template.
___________________
It’s in the detaιls…

demonstration portfolio