0

I'm trying to add the taxonomy term for a blog post to node--blog.tpl.php for the Fusion Framework and the Acquia Prosper Theme, but I've run in to some trouble and I'm not sure why it's not working.

The goal is to have the authorship line look like this:

By Blog Author | Posted Thursday March 14, 2013 | Filed under [Category Taxonomy Term name]

Here is the code I've got in there currently:

<?php if ($display_submitted && isset($submitted) && $submitted): ?>
<div class="submitted terms terms-inline"><em>By</em> <?php print $name; ?> | <em>Posted</em> <?php print format_date($node->created, 'custom', 'l F j, Y'); ?> <?php if $terms: ?> | <em>Filed under</em> <?php print $terms; ?><?php endif; ?></div>
<?php endif; ?>

I've tried several different things, but I can't get anything to work. I'm thinking it should a simple fix, but I've not been able to make it work.

The tpl.php file tells me that $terms should be available to me as a variable, but I've tried everything I can think of to no avail. I'd appreciate any help you can offer!

1 Answer 1

1

If you look at the Drupal 7 documentation for the variables available by default in the node.tpl file, $terms is not on the list: http://api.drupal.org/api/drupal/modules!node!node.tpl.php/7

If you want to display additional variables in your template files (from what's already there by default), you should make sure that these additional variables are actually being set in your template.php file first.

So, go into your theme's directory and find the file called template.php. Does it have one of the following preprocess functions, in which it adds additional variables for your template file:

  • THEME-NAME_preprocess_node() or
  • THEME-NAME_preprocess_node_blog() (assuming your content type's machine name is 'blog')

If either of those exist in your theme's template.php file, look to see if the $terms variable is being set in a statement that should start with

$variables['terms'] = ...

If that is not happening in the template.php file, then the variable is never being set and will be empty.

If your theme's preprocessing isn't somehow prepping that variable for you, however, you can still try printing out your tags this way:

 <?php print render($content['field_tags']); ?> 

Where you can substitute 'field_tags' with any field you have on that node. :-)

4
  • Ok- thank you so much for the response. I do not have those preprocess functions in the template.php file. Here is what's in that file out of the box: code /* Override or insert variables into the html template.*/ function acquia_prosper_process_html(&$variables){ // Hook into color module if (module_exists('color')) { _color_html_alter($variables); } } code Do you have advice for how to best add it? BTW - your second solution code <?php print render($content['field_tags']); ?> code was one of the options I previously tried.
    – Rob Orr
    Commented Mar 14, 2013 at 23:56
  • BTW - the bulk of the template.php is inherited from its parent theme which is Fusion Core, but there are no preprocess funtions for 'terms' there either.
    – Rob Orr
    Commented Mar 15, 2013 at 0:46
  • So you're saying that you can see on the content type that the field you're using to tag has a machine name of 'field_tags' and you're printing that field out with print render($content['field_tags']); and clearing cache and it's not printing it out? You're definitely using the correct field name and clearing cache? Commented Mar 15, 2013 at 15:45
  • Correct essentially. My field name's machine name is 'field_category' and I printed that using the code you mentioned and I wasn't able to get anything to render. I'll double-check the cache, but I'm fairly certain it was cleared and that's the only field with that name.
    – Rob Orr
    Commented Mar 20, 2013 at 23:46

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.