Seems like a pretty easy thing to do, but I am having a hard time in using a variable from function theme_preprocess_block(&$variables, $hook) in template.php in a Block body in admin.

For example, in template.php, I have:-

function theme_preprocess_block(&$variables, $hook) {
  $variables['theme_url'] =  base_path().drupal_get_path('theme', variable_get('theme_default', NULL));


From here, I want to use theme_url variable in Block Body in admin as shown:-

Block admin

It's not happening through the shown way. Any idea how I can achieve that?


2 Answers 2


You can't do that.

The block content doesn't ahve access to variables you add in the block preprocess function. The block preprocess function code runs after the block content has been generated.

Since you have a PHP block just add that code from your preprocess function directly to it.

So put this at the top of your block content:

$theme_url = base_path() . drupal_get_path('theme', variable_get('theme_default', NULL));

Instead of using a PHP block I would recommend to use a template for that block – then you should be able to use your preprocessed variables.

The Community Documentation page about Drupal 7 Template (Theme Hook) Suggestions might be useful for finding the correct name for the block template.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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