[Solved] How to access post thumbnail from Twig template?

I am working on a twig template showing related episodes.

<!-- ===== RELATED EPISODES ===== -->
{% for episode in episode.relatedEpisodes %}
	<div class="podcast-card sidebar">
		<figure class="podcast-image"><a href="{{episode.url}}">{{episode.post.the_post_thumbnail('episode-box')}}</a></figure>
		<div class="podcast-content">
			<span class="podcast-date">{{episode.publicationDate}}</span>
			<h2 class="podcast-title"><a href="{{episode.url}}">{{ episode.title }}</a></h2>
{% endfor %}

This works perfectly except for the post thumbnail. I do not want to show the episode coverart!

I tried using this {{episode.post.the_post_thumbnail('episode-box')}} but it does not work. I use $post->the_post_thumbnail('episode-box') everywhere in my PHP code, so the function is available.

episode.post is the core WP_Post object, not a “Twig-optimized” wrapper like all the other objects. Unfortunately this object is rather useless as it only enables accesss to few metadate (the most useful being episode.post.ID).

WordPress functions like the_post_thumbnail are not available to Twig by default. Some PHP code is necessary to create a Twig wrapper for them. See https://github.com/podlove/podlove-publisher/blob/master/lib/template/twig_filter.php#L83 for example, which makes some WP checks available to Twig.

Thanks! I will see if I am able to use this way to make the post thumbnail function available.