I've created a custom views field following the excelent Creating a custom Views field in Drupal 8 guide. The render method returns the desired output, except that it's being sanitized somewhere down the line and thus the html markup comes out as plain text on the page.

I'd rather put the html markup into the theme, but there doesn't seem to be such thing as


in Drupal8 ?

  • yes, such a template name suggestion for field names does exist: views-view-field--field-name.html.twig, problem is only, that twig debug is not able to display it
    – 4uk4
    May 17, 2017 at 16:00
  • Can you show us your render() method?
    – mpdonadio
    May 17, 2017 at 19:39

1 Answer 1


I can output HTML using my render method. Take a look:

   * {@inheritdoc}
  public function render(ResultRow $values) {

    $field_abnormal_category = $this->view->field['field_abnormal_category']->original_value->__toString();

    if($field_abnormal_category == 'No') {
      $field_category_image = $this->view->field['field_category_image']->original_value->__toString();
    else {
      $field_category_image = '';

    return [
    '#type' => 'inline_template',
    '#template' => $field_category_image

  • Thanks. It works on Drupal 9 too.
    – ZioBudda
    Dec 1, 2021 at 15:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.