What is the easiest way to get the value of a string field in a twig template? I'm using Drupal 8.5.4 and Bootstrap Paragraphs. I have a custom module foo and a custom paragraph type bar defined within. In the template for bar, I use kint to inspect the content of the variable. It turns out it has 17 properties, and none of them are the value of the field. The first 14 of them are in core/lib/Drupal/Core/Field, L#89-102. The last 3 are 0, #cache, and weight.

Digging into the object, I found the field value in content.bar.0['#context'].value. Obviously using this method to access a simple field value is janky as hell, and I would prefer not to have to do this every time.

Two questions:


Is there a simpler way to access the field value? I don't mind using a twig filter if need be
Is there a way to configure my paragraph types to pass the context to the template, rather than all of the field data?
You are referring to paragraph--bar.html.twig? Then this depends on what you want to do with the value.

Render the field value:

{{ content.field_example }}


Write code with it:

{% if paragraph.field_example.value == 'foo' %}
  &lt;p&gt;The field value is "foo".&lt;/p&gt;
{% endif %}


See this blog post for node.html.twig, which applies here as well, only that the entity is paragraph. instead of node.: https://www.md-systems.ch/de/blog/techblog/2017/02/20/twig-and-entity-field-api-or-how-to-take-control-of-nodehtmltwig