drupal-6


How does one get Drupal's current view/page identifier?


What I am looking for is a page_id/view_id that I can use to identify and style specific pages. I would use the title or the url, but there is a chance that it could change if the a higher-up decides that the page should no longer be called Golf, but rather Tee-Time because he likes it better.
Presumably this identifier would not change if the current page were to be a paged view (page 1,2,3,4...).
One way of solving this is the following. It's depending on the url, so if it changes, so does the class-name.
In my themes template.php I implemented hook_preprocess_page:
function mytheme_preprocess_page(&$vars, $hook) {
$body_classes = array();
$body_classes[] = 'page-' . _get_page_name($_SERVER['REQUEST_URI']);
$vars['body_classes'] = implode(' ', $body_classes);
}
function _get_page_name($request_uri) {
static $numeric_subsection = array(
'/node/' => 'node',
);
$preAlias = $request_uri;
$alias = substr(strrchr($preAlias, "/"), 1);
if (strpos($alias, '?') > -1) {
$alias = substr($alias, 0, strpos($alias, '?'));
}
$page_name = $alias;
if (empty($alias)) {
$page_name = 'start';
}
else if (is_numeric($alias)) {
foreach ($numeric_subsection as $section => $pn) {
if (strpos($preAlias, $section) > -1) {
$page_name = $pn;
}
}
}
return $page_name;
}
Then in the main page-template:
<body class="<?php print $body_classes; ?>">
This isn't a generic solution. So you'll probably have to customize this for your specific needs. It will for example need som tweaking to play nicely with path auto.
This depends a little on how your site is put together (panel pages, view pages, "normal" pages). Essentially, you need to figure out what vars are in scope, and then determine which information in them can be used. To determine what is in scope, you can use print_r(array_keys(get_defined_vars())); and then poke around in the individual vars.
An option is to do something in theme_preprocess_page. One option is to get the page data via page_manager_get_current_page(), poke around in there, and then add body classes as needed. Without knowing what you are doing, you essentially need to print_r the results somewhere, look at what you have, and go from there.

Related Links

Drupal website breaking in IE 8, 7 - theme not getting applied
Drupal 6 db_query files table
CCK field value count never less than 1 or NULL
hook_menu Title
Drupal autocomplete fails to pull out data as a subdomain
show administration theme when editing page in drupal
Get root taxonomy name in drupal view
Drupal content title doesn't show
Content administer page
Allowing Users to create custom groups of Countries
Drupal: Horizontal Menu
Drupal6 - Export bulk node
Drupal 6 <front>/node lists all nodes (unwanted)
Drupal 6 Syntax Highlighting
Theming node body in Drupal 6
Changing cck fields on content page edit with taxonomy

Categories

HOME
gitlab
google-play
raspberry-pi
session
octobercms
alfresco
getelementsbytagname
rsync
jira
spring-jdbc
youtube-api-v3
dxl
jpeg
fsm
ravendb
echarts
swagger-ui
ios-charts
bs4
adfs
basic
facebook-messenger-bot
windows-10-universal
midi
google-cloud-ml
telephony
angular-ui
paging
orleans
arabic
chromium-embedded
language-agnostic
blazemeter
qhull
centos6.5
publish
elasticsearch-ruby
procdump
oracle-fusion-middleware
google-qpx-express-api
catch-all
commit
wallpaper
amazon-kinesis-kpl
nssegmentedcontrol
fusionpbx
vxworks
space-complexity
espeak
sqlite2
jna
ncalc
dynamic-reports
vao
qcombobox
skeleton-css-boilerplate
angular-resource
long-polling
dandelion
ionicons
veracode
yii2-extension
aurelia-validation
kbuild
magma
nbconvert
lync-client-sdk
dynamics-sl
blacklist
firmata
google-web-starter-kit
gridview-sorting
angstrom-linux
prettytensor
javax.sound.midi
kendonumerictextbox
msys
lemon
atk4
tmuxinator
computer-algebra-systems
angular-leaflet-directive
sonarqube5.1.2
pretty-print
fscommand
modalpopup
clicktag
xceed-datagrid
oam
type-equivalence
free-variable
manchester-syntax
cufon
gnu-prolog
psi
dbal
noscript

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App