By nroper on
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
You can access the elements
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.
Doesn't reconnise alias
Hi,
Thanks for this. Only problem is that it doesn't return info from the alias.
Nick
categorisation?
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
You can also make more
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