how to check messages exists
While the page.highlighted variable contains the block data (mytheme_messages) for message display, the block rendering data doesn't contain the messages themselves, so there's no way to check for message existance there.

However, you can inject a custom variable based on the current message queue from drupal_get_messages(). 

For example, in your MYTHEME.theme:

/**
 * Implements hook_preprocess_page() for page.html.twig.
 */
function MYTHEME_preprocess_page(array &amp;$variables) {
  // Inject a flag based on the current message queue.
  $variables['available_messages'] = !empty(drupal_get_messages(NULL, FALSE));
}


And within your page.html.twig:

{% if available_messages == true %}
   &lt;!-- TODO: Add custom markup when there are messages --&gt;
{% endif %}