How to get media entity field value in twig? Sometimes it is necessary to get the actual value of a field (not the formatted/rendered one), e.g. to check a boolean for true or false.

If I want to get a field value of a node or paragraph inside twig templates (node.html.twig / paragraph.html.twig) I can use node.field_my_boolean.value respectively paragraph.field_my_boolean.value. 

How do I accomplish this in a media twig template? I've already tried media.field_my_boolean.value but it does not work.
Right now, the Media module does not pass its object in the variables like Paragraphs and Node does. This is why media.field_my_boolean.value does nothing.

You can correct this in your theme by implementing theme_preprocess_media, which adds the media object to the variables:

/**
 * Prepares variables for media templates.
 *
 * Default template: media.html.twig.
 *
 * @param array $variables
 *   An associative array containing:
 *   - media: An individual media for display.
 */
function mytheme_preprocess_media(&amp;$variables) {
  $variables['media'] = $variables['elements']['#media'];
}


You can then access media. in your twig template and any connected fields on it just like Paragraph or Node.