3

I have a region--content.tpl.php and am trying to figure out how to print the $submitted variable (usually printed in node.tpl.php).

--- EDIT ---

Including here the final code I used. This lets you print out the themed user link where as the original code only printed the name as plain text.

function theme_preprocess_region(&$vars) {
  if ($vars['region'] == 'content') {
    $node = menu_get_object();
    $user = user_load($node->uid);

    if ($node) {
      // Adapted from template_preprocess_node().
      $vars['submitted'] = 'By ' . theme('username', array('account' => $user)) . ' | ' . format_date($node->created, 'short');
    }
  }
}

1 Answer 1

1

The region template has no concept of the page context, so it doesn't know about the node by default.

You can give it that context by implementing hook_preprocess_region() in your theme's template.php file (or a module file), and seeing if there's a node available there:

function MYTHEME_preprocess_region(&$vars) {
  if ($vars['region'] == 'region_name') {
    $node = menu_get_object();

    if ($node) {
      // Adapted from template_preprocess_node().
      $vars['submitted'] = t('Submitted by !username on !datetime', array('!username' => $node->name, '!datetime' => format_date($node->created)));
    }
  }
}

After you clear the caches, your region template on node pages should have the $submitted var available to it. Obviously that might need a bit of tweaking to suit your needs.

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.