0

作成したテンプレート ファイルをレンダリングするために、モジュール内でカスタム ブロックを取得できないようです。これが私のコードです:

<?php

include_once 'e_most_popular.features.inc'; //this is from features module

function e_most_popular_block_info() {
   $blocks['e_most_popular'] = array(
     'info' => t('e_most_popular block TITLE'), 
     'cache' => DRUPAL_NO_CACHE, //there are a number of caching options for this
   );



  return $blocks;

}



function e_most_popular_block_view($delta = ''){

  switch($delta){

    case 'e_most_popular':

      if(user_access('access content')){ //good idea to check user perms here

         $block['subject'] = t('MYblock_TITLE');

         $block['content'] = e_most_popular_block_function_items();

      }

      break;

  }

}



function e_most_popular_block_function_items(){

  $items = array();

  $items['VAR_ONE'] = array('#markup' => 'VAR_ONE_OUTPUT'); //this is the simplest kind of render array

  $items['VAR_TWO'] = array(

                        '#prefix' => '<div>',

                        '#markup' => 'VAR_TWO_OUTPUT',

                            '#suffix' => '</div>',

                          );

//this is where the $items get sent to your default e_most_popular_block.tpl.php that gets //registered below

      return theme('e_most_popular_block_function_items', array('items' => $items)); 

    }



//here you are registering your default tpl for the above block 

function e_most_popular_theme() {   

  $module_path = drupal_get_path('module', 'e_most_popular');

  $base = array(

    'path' => "$module_path/theme",   );

     return array(

    'e_most_popular_block_function_items' => $base + array(

      'template' => 'e_most_popular_block',  

      'variables' => array('items' => NULL,),

    ),   

  ); 

}

正しく名前が付けられていないとエラーになるため、テンプレートファイルを読み取ることを確認し、ブロックメニューのサイドバーにブロックを割り当てたモジュールを有効にしました。また、変更後にキャッシュをクリアします。まだ出力が得られません。テンプレートファイルは次のとおりです。

Template file Test
<?php 

$items = $variables['items'];
print render($items['VAR_ONE']); 

私が間違って何をしているのか分かりますか?

4

1 に答える 1

1

コメントで述べたように、問題は、hook_block_view で $block 変数を返していないことです。そのため、何も出力されていません。

hook_block_viewのドキュメントを確認してください。

hook_block_view は次のようになります。

function e_most_popular_block_view($delta = ''){
  $block = array();

  switch($delta){

    case 'e_most_popular':

      if(user_access('access content')){ //good idea to check user perms here

         $block['subject'] = t('MYblock_TITLE');

         $block['content'] = e_most_popular_block_function_items();

      }

      break;

  }
  return $block;
}
于 2013-03-12T21:12:19.420 に答える