S
S
semki0962017-02-20 17:38:42
Drupal
semki096, 2017-02-20 17:38:42

How to replace all spaces with underscores as a result of views output in a text field?

How to replace all spaces with underscores as a result of views output in a text field? Probably you can create a field template, but maybe there is another way? Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Yankovsky, 2017-04-07
@semki096

Something like this:

function YOU_MODULE_NAME_preprocess_views_view_field(&$vars) {
  $view = $vars['view'];
  $field = $vars['field'];

  if ($view->name == 'name' && $view->current_display == 'display' && $field->field_alias == 'alias') {
    $vars['output'] = str_replace(' ', '_', $vars['output']);
  }
}

Be careful with $field->field_alias if the code above does not work, it's most likely that you did not specify it correctly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question