2

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

views-view-field-<fieldname>.html.twig

in Drupal8 ?

2
  • 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
    Commented May 17, 2017 at 16:00
  • Can you show us your render() method?
    – mpdonadio
    Commented May 17, 2017 at 19:39

1 Answer 1

4

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
    ];

  }
0

Your Answer

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

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