I am using Drupal 8 and trying to theme video-embed-iframe.html.twig by content type. with the current naming suggestions this is not possible.

I am using Media with video embed field containing in a field called video

This is what I did so far. in the fields template named above in the templates folder of my theme

{% if logged_in %}
 <iframe{{ attributes }}{% if url is not empty %} src="{{ url }}{% if     
 query is not empty %}?{{ query | url_encode }}{% endif %}"{% endif
{% else %}

 <div id="promotion">
 <div id="promotion-image">
   <div id ="promotion-bg">
 <div id ="promotion-text">
 <H1>Eine brilliante Überschrift</H1>
 <span id="promotion-attribution">
 <a href="http://somesite.com">Credit author of the background image</a></span>
{% endif %}

I have no clue how to access the field by content type to separate the code deepening if you have a content type eg page and article Any Ideas?

Is there a way to populate a global var like logged in containing the mashine name of the content type without needing a custom module. I other words is there a way to populate a var like

contenttype=anycotenttypehere in the mytheme.theme file by writing a function? to be able to display the video depending on with contetnt type has been used and if the user is logged in or not

1 Answer 1


That's not easily possible, not directly.

By default a media entity is going to be render cached on its own, that means the same media could be used in two different nodes with a different type and as long as they use the same view mode, it is only going to be built once. While you can get the current node easily on the detail page in preprocess and you could vary the rendered media by path, that will possibly result in a lot of variations and won't really work on views and other pages that display teasers of many nodes.

The easist way to achieve something like this would be to define two different view modes, use one from one node type and the second from the other.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.