Get value from twig tweak without additional markup I am using the following code to set a variable "tab1visibility" from the twig tweak value for field_hidden based on a block id.  {% set tab1visibility =  drupal_field('field_hidden', 'block_content', 7)  %}

This works perfectly but returns the value with the expected markup.

When I try to use |striptags on this newly created value it returns nothing. 

So

{% set tab1visibility =  drupal_field('field_hidden', 'block_content', 7)  %}

&lt;p&gt;{{tab1visibility}}&lt;/p&gt;


returns true or false wrapped in my typical field div templating.

{% set tab1visibility =  drupal_field('field_hidden', 'block_content', 7)  %}

&lt;p&gt;{{tab1visibility|striptags}}&lt;/p&gt;


returns nothing no markup or the raw value.

How do I get just the value without the surrounding markup?
A field formatter stores the field object inside of the render array for reference later, so that you can still access the raw values:

{% set field = drupal_field('field_example', 'block_content', 1) %}
{% set value = field['#items'].0.value %}
{{ value }}


This is the same for all field formatters.



Your approach might also work, if you |render the field first and then apply |striptags:

{{ tab1visibility|render|striptags }}


But not in a consistent way, because it depends on the specific field type and the configured field formatter.