0

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 ?

  • 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 – 4k4 May 17 '17 at 16:00
  • Can you show us your render() method? – mpdonadio May 17 '17 at 19:39
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
    ];

  }

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.