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

Lightbox2 and youtube videos
drupal 6 - unset previously set cck field validation error messages
display only the content of a page in lightbox2 in drupal
Drupal show error when move to the new Hosting [duplicate]
Ubercart 2.x - Add produkt line to order via php
How to display html content in block in Drupal 6?
How to use Drupal View
relate registered user to specific content in drupal 6
How to link a user with taxonomy terms
Populating a view in Drupal
Drupal Views 6.x-2.x not rendering correctly
What is the relationship between the primary menu links and secondary menu links in drupal?
Drupal 6 Availability of View Basic Settings Variables
DRUPAL6 FORM FAPI WITH DRUPAL_RENDER
manage field in create content is not appearing drupal 6
change the order of a block in a particular page - drupal6 using hook

Categories

HOME
winforms
amazon-ec2
omnet++
heroku
relayjs
spagobi
setup-deployment
cmd
yarn
installshield
enterprise-library-5
datastax-java-driver
ios-charts
dacpac
facebook-php-sdk
user-input
midi
quicklook
quickbooks
moonmail
static-libraries
messages
workload-scheduler
worldwind
http-status-code-504
oracle-coherence
code-review
karma-jasmine
introduction
emulator
java-3d
physics-engine
excel-2007
cultureinfo
spark-jobserver
apache-commons-io
wpfdatagrid
intel-pin
info.plist
publish
compatibility
google-cloud-nl
junit5
bosh
twilio-api
hybridauth
android-kernel
rotational-matrices
bytecode-manipulation
ios5
overlap
revolution-slider
stacked
disassembling
serverside-rendering
c11
uft-api
ansible-playbook
greenrobot-eventbus
sas-visual-analytics
email-templates
galen
http-redirect
netcdf4
scorm
apple-news
skeleton-css-boilerplate
angular-resource
long-polling
jsch
appcompat
boost-multi-index
svmlight
blacklist
or-tools
quartz-composer
probability-density
prettytensor
superstack
pagerank
ios4
oauth2client
atk4
truevault
lustre
javax.mail
codeigniter-url
tablelayout
coldbox
android-imagebutton
rdtsc
socketexception
markers
kgdb
android-2.2-froyo
resty-gwt
terminal-services
soundtouch
seed
html-editor
google-email-migration
runas
cufon
genshi
cinema-4d
winbugs14
inotifycollectionchanged
iphone-web-app
sortable-tables
gallio
thread-local-storage
mediarss

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App