drupal 7 custom content hook_theme output

大兔子大兔子 提交于 2019-12-11 07:29:16

问题


I have a custom module created in Drupal 7 and I want it to display some HTML content. Here is how I have did.

But it is not working, what I do wrong?

<?php

/**
 * Implements hook_block_info().
 */
function submenus_block_info() {
    $blocks = array();

    $blocks['info'] = array(
        'info' => t('The submenu zone')
    );

    return $blocks;
}

/**
 * Implements hook_block_view().
 *
 */
function submenus_block_view($delta = '') {
    $block = array();
    $users = "edf";
    $title = "sdfsd";
    $block['subject'] = t('Submenu');
    $block['content'] = theme('submenus_output', array('users' => $users, 'title' => $title));
        return $block;
}

/**
 * Implement hook_theme()
 */
function submenus_theme() {
    return array(
        'submenus_output' => array(
            'variables' => array('users' => NULL, 'title' => NULL),
        ),
    );
}

/**
 * Display output
 */
function theme_submenus_output($somearray) {
    $content = '<div>TEST</div>';

    return $content;
}

?>

回答1:


I checked, there is nothing wrong with that code: the new block is available in the list of blocks, and if you assign it to a region, the block is called and the code from the custom theme function is displayed.


So you could try these things:

  • in Administration > Configuration > Development > Performance, clear the caches

  • in Administration > Structure > Blocks, make sure the block is assigned to a region that exists (such as "Content") and if it is, click the "Configure" link to see if there is a filter that prevents it from being displayed.



来源:https://stackoverflow.com/questions/5167770/drupal-7-custom-content-hook-theme-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!