0

just wanted to scope peoples thoughts on the best way to do this: I have a node which surfaces taxonomy terms. I need to pass them to a custom block (templated with block.tpl.php).

The terms can be see within the node using devel, but i'm unclear as to how best pass them into the custom block.

any thoughts would be greatly appreciated

3
  • inside the code that builds your block, you can use menu_get_object() to grab the node it is sitting upon, and from there, grab the tax terms.
    – Jimajamma
    Commented May 1, 2013 at 16:16
  • IS this within the block.tpl.php or is menu_get_object() only for preprocess function? Commented May 1, 2013 at 16:22
  • you can use it within your block template, but you really should put it in a preprocess function just to keep the template as "clean" as possible.
    – Jimajamma
    Commented May 1, 2013 at 16:24

1 Answer 1

1
/**
 * Override or insert variables into the block templates.
 *
 * @param $variables
 *   An array of variables to pass to the theme template.
 * @param $hook
 *   The name of the template being rendered ("block" in this case.)
 */

function MYTHEME_preprocess_block(&$variables) {

  if ($variables['block_id'] == 'target_block_id') {

    //load node object
    $node = menu_get_object();

    // do something with node object

    // add variable to your block template file
    $variables['block_variable'] = 'something';
  }
}

Available block variables - Block variables

0

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.