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.

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

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料