Skip to main content
  • Guides & Documentation

Knowledgebase

Featured articles, how-to guides and quick tips.

Getting a (Very) Raw Field Value in Twig - Drupal 8

So, you need to output a field value (the entity title, body field — or even a custom field), completely raw.

You don't want any HTML markup present, and you don't want any unwanted spaces surrounding the value, which are likely inherited from a field.html.twig template somewhere within your theme, or Drupal core.

I'm sure you've already tried various solutions and syntaxes, but there's one surefire syntax that works every time.

Of course, since you're using Drupal 8, you'll be using Twig as your templating engine.

So in whichever template file you're targeting, simply use the following syntax:

{{ content.title.0 }}

This should render the raw value, sans any additional markup or whitespace, and should work for pretty much any field — even default fields supplied by Drupal core, like the title and body fields.