0

I am working on Advanced forum. And for my need I am editing advanced-forum.naked.post.tpl.php and I want to add the author name at one place. But this template do not have author name, but it has entire author pane printed. Now the variable for the author name is in advanced-forum.naked.author-pane.tpl.php. And it has a author-name code

<?php /* Account name */ ?>
      <div class="author-pane-line author-name">
        <?php print $account_name; ?>
   </div> 

now if I am direct pasting this code to advanced-forum.naked.post.tpl.php, it shows error, that variable is not defined. Moreover, both this tpl files are in the advanced forum module/style file. So, how can I access that variable in that .tpl.php file? Very Thanks.

2

You can add custom variables using hook_preprocess_node() in your theme's template.php file.

Here's how to add the account name:

function YOUR_THEME_preprocess_node(&$variables) {
  $variables['account_name'] = format_username($variables['account']);
}
1

you need to set it in the preprocess function of the template. or see this answer https://stackoverflow.com/questions/2383865/how-do-i-use-theme-preprocessor-functions-for-my-own-templates

you'll need to hook this preprocess function

/**
 * Preprocesses template variables for the author pane.
 */
function advanced_forum_preprocess_author_pane(&$variables) {
  // Author pane is used in various places. Check the caller to make sure
  // we are the one that called it.
  if (!empty($variables['caller']) && $variables['caller'] == 'advanced_forum') {
    advanced_forum_add_template_suggestions("author_pane", $variables);
  }
}

maybe the author pane module could do the job for you ;) here's a similar question How to modify Author Pane date fields?

  • I am reading and understanding all this links...will let you know further. – CodeNext Mar 22 '16 at 19:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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