views:

926

answers:

2

How can I get a value from a preprocess function to template.php, in a function named sitename_modulename_user_loginblock($form)?

I created the value in the preprocess function with a custom query so I could do that in the loginblock function itself, but only $form is available there and I need 3 other variables to construct the query.

the loginblock function returns $output which is markup and a few variables. afaik there is no additional step between this function and the display of its return value on the page?

A: 

to pass from a preprocess function to the template.php populate the $vars[] array, the key you specify will be a variable name in the template and the value the variable value so:

$vars['foo'] = "bar";

in your preprocess function will create $foo in your template with a value of "bar"

I am a little confused about what you are trying to do. Ideally logingblock would be a block, rather than something created in preprocess. You may want to look at that option.

Jeremy French
I'm not sure either, but I think he does not mean passing variables to a template file, but to a function overridden in the themes template.php file, which would not be possible, afaik.
Henrik Opel
A: 

As Jeremy stated, it is not really clear what you want to do, so maybe you should edit your question to clarify.

To me it sounds as if you want to override the default user_login_block() function with a custom version in your themes template.php. If that is the case, you can not pass variables there from a preprocess function, as those only prepare variables for their corresponding *.tpl.php files.

This article on overriding form functions might be helpful, depending on what you want to achieve.

The naming is significant. For the function to work as an override, you'd have to name it themename_user_loginblock($form).

Henrik Opel