0

I've got a content type with fields whose values are URLs. I'd like to use a view to display these as links, using the field label as link name, something like <a href="{field_value}">{field_label}</a>.

I've got the field values displaying correctly. I just can't figure out how to turn them into links like above (or if this is even possible).

How can I achieve this?

1

You can use REWRITE RESULTS with REPLACEMENT PATTERNS

<a href="[field_value]">Any Text</a>

Example
If i want to edit any node

<a href="node/[nid]/edit">Any Text</a>
  • [field_value] is okay but I am not sure if Views can get [field_label] for you like this – gauravjeet Jul 26 '17 at 9:20
0

use hook_views_pre_render()

MYMODULE_views_pre_render(&$view) {
  if ($view->name == '<Your-view-name>') {
    foreach($view->result as $key => $row) {
      // change field values to href, or whatever for every row
    }
  }
}

OR, if this looks too complex and cumbersome, you can go for template preprocess for one of the templates under Theme information in Views UI.

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.