4

Is there a way to rewrite the content of a field displayed in a view?

E.g. If my title is long, like "[Product ID:5739] Ninja Stars" and I want it to display just "Ninja Stars" in the view, how can I do it?

5

You can in views rewrite the result of any field, or trim most fields, but if there is some logic to what you want to remove you would need to do with with a preprocess hook in your theme. In this case it sounds like you need to do the latter. Something like this should do the trick:

function theme_preprocess_views_view_fields(&$vars) {
  if ($do_your_checks) {
    $vars['fields']['field_name'] = preg_replace(...) // Use regular expression to change title.
  }
}
| improve this answer | |

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.