duanmo7075 2014-01-19 21:36
浏览 74
已采纳

Drupal:从自定义.module创建变量到自定义.tpl.php

I create a custom module and I want use the complete_url of my future website in the template who used/created by my module.

I tried several ways and searched Google but I don't find a solution. However this issue seems very simply, that became me crazy x)

So, I must create a variable in my .module and add her when I return the array in the main_socialtag_theme function. Where/How can I do that ?

My .module:

function main_socialtag_block_info(){
    $block['main_socialtag']=array(
        'info' => t('Main socialtag'),
        'cache' => DRUPAL_NO_CACHE,
    );
    return $block;
}

function main_socialtag_theme(){    
    return array(
        'main_socialtag_block' => array(
            'template' => 'theme/main_socialtag_block',
            'variables' => array(),
        ),
    );
}

function main_socialtag_block_view($delta=''){
    if ($delta == 'main_socialtag'){    
        return array(
            'subject' => '',
            'content' => array(
                '#theme' => 'main_socialtag_block',
            )   
        );
    }
}

Thanks for help, and sorry for my bad english writing !

  • 写回答

1条回答 默认 最新

  • dongxin1999 2014-01-21 10:12
    关注

    If you are looking for a way to add, modify and call variables. Check variable_get and variable_set.

    To add or modify a variable value:

    variable_set("my_variable_name", "value");
    

    To retrieve the value:

    $myVal = variable_get("my_variable_name", "");
    

    For hook_theme Implementation, kindly check this question.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 cocos2d-x lua 在mac上接入lua protobuf?
  • ¥15 es 7.17.20版本生成时间戳
  • ¥15 wpf dategrid表头排序图标自定义
  • ¥15 xshell无法连接提示ssh服务器拒绝密码
  • ¥15 AT89C52单片机C语言关于串口通信的位操作
  • ¥20 需要步骤截图(标签-服务器|关键词-map)
  • ¥50 gki vendor hook
  • ¥15 灰狼算法和蚁群算法如何结合
  • ¥15 写一个利用ESP32自带按键和LED控制的录像代码
  • ¥20 stm32f103,hal库 hal_usart_receive函数接收不到数据。