HTML Drupal身体类

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HTML Drupal身体类相关的知识,希望对你有一定的参考价值。

<?php
/**
*  This snippet creates a <body> class and id for each page.
*
* - Class names are general, applying to a whole section of documents (e.g. admin or ).
* - Id names are unique, applying to a single page.
*/
// Remove any leading and trailing slashes.
$uri_path = trim($_SERVER['REQUEST_URI'], '/');
// Split up the remaining URI into an array, using '/' as delimiter.
$uri_parts = explode('/', $uri_path);

// If the first part is empty, label both id and class 'main'.
if ($uri_parts[0] == '') {
    $body_id = 'main';
    $body_class = 'main';
}
else {
    // Construct the id name from the full URI, replacing slashes with dashes.
    $body_id = str_replace('/','-', $uri_path);
    // Construct the class name from the first part of the URI only.
    $body_class = $uri_parts[0];
}
/**
* Add prefixes to create a kind of protective namepace to prevent possible
* conflict with other css selectors.
*
* - Prefix body ids with "page-"(since we use them to target a specific page).
* - Prefix body classes with "section-"(since we use them to target a whole sections).
*/
$body_id = 'page-'.$body_id;
$body_class = 'section-'.$body_class;
print "<body class="$body_class" id="$body_id"";
print theme('onload_attribute');
print ">";
?>

Drupal 6个独特的身体类

Automatically add a class to the body tag on each page. Remember to add
  1. /**
  2.  * Override or insert PHPTemplate variables into the templates.
  3.  */
  4. function phptemplate_preprocess_page(&$vars) {
  5.  
  6. // Add unique classes for each page and website section
  7. $path = drupal_get_path_alias($_GET['q']);
  8.  
  9. // append the body classes array with the current path
  10. $body_classes[] = phptemplate_format_class('page-' . $path);
  11.  
  12. // set body_classes var with spaces in between each class
  13. $vars['body_classes'] = implode(' ', $body_classes);
  14. if (module_exists('path')) {
  15. $alias = drupal_get_path_alias(str_replace('/edit','',$_GET['q']));
  16. if ( $alias != $_GET['q'] && $alias == $_REQUEST['q'] ) {
  17. $suggestions = array();
  18. $template_filename = 'page';
  19. foreach (explode('/', $alias) as $path_part) {
  20. $template_filename = $template_filename . '-' . $path_part;
  21. $suggestions[] = $template_filename;
  22. }
  23. }
  24. $vars['template_files'] = $suggestions;
  25. }
  26. }
  27. //Helper Function for formatting css class names
  28. function phptemplate_format_class($string) {
  29. return strtolower(preg_replace('/[^a-zA-Z0-9_-]+/', '-', $string));
  30. }

以上是关于HTML Drupal身体类的主要内容,如果未能解决你的问题,请参考以下文章

Drupal身体类

Drupal 6个独特的身体类

Drupal 视图 2 提要显示将周围的 html 添加到项目

管理模板中的完整内容,预告片和修剪内容

身体标签上的类别或 ID

在 Drupal 8 站点中找不到类“DOMDocument”