Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

i want set a variable in module and use it in my theme, (except variable_set and variable_get way.)

for instance . in module file

      if(in_array(arg(1),$ex))
      {
//      set a variable
      }

in theme file

if(//variable)
{
echo '<div class=d7></div>';
}

thank you so much for help me

share|improve this question

1 Answer

up vote 0 down vote accepted

HOWEVER:

You should really look into the various _preprocess() hooks. From further commentary below, I am thinking that's where you should be doing all this.

ORIGINAL ANSWER:

If you don't want to use the system wide variable_set() or variable_get() you can always set a variable in the global $_SESSION array that would be seen by the current logged in user only, eg,

if ( // whatever ) {
  $_SESSION['MYMODULE_variable_name']= // whatever
}

SUPER DUPER OVER SIMPLIFIED ADDITION:

function MYMODULE_foo($value=NULL) {
  static $bar;

  if ($value) {
     $bar=$value;
  }

  return $bar;
}

accomplishes it inside your module, eg, you can do:

MYMODULE_foo('this is cool');

and then in your theme do:

$baz=MYMODULE_foo();
share|improve this answer
hi and thank you . i use from hook_node_load,but i don`t khonw how use from your code in this hook . i need help more for this Problem – mohsen Apr 13 '12 at 16:25
in MYMODULE.module, you would just put the _foo() function, and then anyplace you want to set the variable you would call the first example, and anywhere you wanted to get the variable, you would call the second example. Or, you could use the _SESSION way first suggested anywhere. – Jimajamma Apr 13 '12 at 16:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.