0

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 !

Muhammad Reda
  • 26,379
  • 14
  • 93
  • 105
spacecodeur
  • 2,206
  • 7
  • 35
  • 71

1 Answers1

1

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.

Community
  • 1
  • 1
Muhammad Reda
  • 26,379
  • 14
  • 93
  • 105
  • Thanks for your answer Muhammad =) this way works perfectly (I keep this x) ), but this isn't the best practice way no ? It's not possible to declare a variable in my custom module and pass her when I return the array of _theme function ? (the line : "'variables' => array()," ) – spacecodeur Jan 21 '14 at 15:10
  • What exactly you need to achieve? – Muhammad Reda Jan 21 '14 at 15:14
  • Your solution is good for my probleme. Now, i'm just looking for the best practice and I think (but, maybe I mistake) the better is to pass the variable via this line "variables' => array()," (function _theme). – spacecodeur Jan 21 '14 at 15:18
  • Are you looking for how to implement `hook_theme`? – Muhammad Reda Jan 21 '14 at 15:20
  • Yes I looked, but I don't find any example who show how pass a sample variable from custom module to custom template. (Drupal 7) – spacecodeur Jan 21 '14 at 15:24
  • Check this link http://stackoverflow.com/q/12985689 I have also added the link to my answer. – Muhammad Reda Jan 21 '14 at 15:28
  • I see your another solution :p It work like a charme, thank you very much Muhammad ! I use a modulename_preprocess function =) – spacecodeur Jan 21 '14 at 22:25