Display Audio File Description in node.tpl.php (Drupal Media module)

The audio field widget that is included in the Media module is great! You add a File field to your content type with the Media Browser widget. This allows you to create nodes and upload audio files and they display with a lovely little audio player without any effort on your part.

Here is what the audio field looks like in the node edit form.

audio-description

Here is what it displays like.

player

This is all wonderful, but I recently had a request to allow for multiple Audio files being attached to a single node. This was a quick setting change, of course, but I realized when you have multiple audio players on screen, you likely want a label or description to be displayed for each.

As you can see above, there is a description field, but it is only displayed if you opt to display the audio file as download link and you use a token.

I wanted it to display above each player. Here’s how I did it.

I created a theme template override for the content type (“concert”). I named the file:

node--concert.tpl.php

…and saved it to my sites/all/themes/mytheme/templates/nodes directory.

Here is my code. Yours will vary as you may be doing special things with other fields in this template as well.

Once you save this file, Flush all caches. You will now see the description field above each audio player.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s