PHP Drupal 6 - 停止向块ID提供哈希名称的视图 - 块预处理

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP Drupal 6 - 停止向块ID提供哈希名称的视图 - 块预处理相关的知识,希望对你有一定的参考价值。

<?php

/**
 * Hook Preproccess Block
 */
function phptemplate_preprocess_block(&$vars) {
  $block = $vars['block'];
  $chars_delta = strlen($block->delta);
  // don't do anything if this block is not from views module or if delta < 32 chararacters
  // because md5 is always 32
  if ($block->module == 'views' && $chars_delta >= '32') {
     //get from variable table the hashes and their corresponding views name, in an associative array
     $hashes = variable_get('views_block_hashes', '');
    // add a nice new template suggestion if this delta is a hash
    if(isset($hashes[$block->delta])) {
       $block->custom_classes['block_id'] = $block->module .'-'. $hashes[$block->delta];
       $vars['template_files'][] = $block->custom_classes['block_id'];
    }
  }
  else { 
    // just set the normal block id for css
    $block->custom_classes['block_id'] = $block->module .'-'. $block->delta;
  }
}

?>



/*How to call this in block.tpl.php*/
<div id="block-<?php print $block->custom_classes['block_id']; ?>" class="clear-block block block-<?php print $block->module ?>">

以上是关于PHP Drupal 6 - 停止向块ID提供哈希名称的视图 - 块预处理的主要内容,如果未能解决你的问题,请参考以下文章

Drupal 6 视图 2:PHP 片段

PHP 向Drupal菜单项添加唯一ID

PHP Drupal 6自定义登录块

PHP Drupal 6个独特的身体类

PHP Drupal 6 Views2嵌入

PHP Drupal 6:动态更改菜单链接标题