| Drupal

drupal-views-linksThis blog post is the answer to a common request we get from people learning how to use Views.

The question is: "How do I automatically add a link to a field"?

The answer is straightforward, once you know how.

Imagine that you have a content type that looks like the image below. You have an active link using the Link module and also some other fields.


Now imagine that we're using Views to show some of items in that content type. Here's a photo gallery using Views. If you don't know how to do this, use our tutorial "Creating a Photo Gallery in Drupal 7".


Now let's show you to automatically add links.

In this example, we're going to automatically link the Movie Poster field to the "Official Website" field.

Inside our view, the image below shows how the fields look currently. We have a Title and Movie Poster field.


We're going to add the Movie Poster field.

  • Click "Add" next to "Fields"
  • Choose "Official Website"
  • Check the "Exclude from display" box because we don't want this to be visible.
  • Save the field. It should show at the bottom of the three fields.
  • Click the "Rearrange" button under "Add"
  • Rearrange the fields so that the Official Website field is before the Movie Poster field.
  • Click the Move Poster field.
  • Check the "Output this field as a link" box.
  • Scroll down to the Replacement Patterns area.
  • Find the replacement pattern for the Office Website field.
  • Copy the replacement into the "Link path" field:
  • Save the field and then save the view.

You've finished and your movie posters will be automatically linked to the official website.

About the author

Steve is the founder of OSTraining. Originally from the UK, he now lives in Sarasota in the USA. Steve's work straddles the line between teaching and web development.