I have used Drupal 7 for a while, but am only starting to learn to use the tpl and template.php files. As you would expect, I have become good friends with the documentation, but am still having trouble putting all the pieces together at times.
One thing that I have not figured out how to do, but seems pretty basic, is to create a function in template.php or a custom tpl file (not sure what I need as well as how to do it) that outputs HTML. Let me explain what I mean…
I have created a custom node–content-type.tpl.php. In there, I have put the following code in to replace the normal submitted by information:
<?php if ($ display_submitted): ?> <div class="submitted"> <div class="created"> <span>Created by <?php print $ node->name; ?> on <?php print format_date($ node->created, $ type = 'medium'); ?>.</span> </div> <div class="revised"> <span>Last revised by <?php print (user_load($ node->revision_uid)->name); ?> on <?php print format_date($ node->changed, $ type = 'medium'); ?>.</span> </div> </div> <?php endif; ?>
I am trying to figure out how to reuse this code in some of my other custom node tpl files without simply cutting and pasting it in. I am obviously missing something basic. How can I go about doing this?