Print image from filepath in Twig I have a paragraph with an image field. If the image field is empty, I want to display a default value. I do not want to just set the default image because an editor could remove that. Here is my code so far:

{% if content.field_image|render = true %}
    {{ content.field_image }}
{% else %}
    {% include "/themes/mytheme/img/my_img.png” %}
{% endif %}


How can I get the image at that filepath to show up in the template?
For example if your default image called default_img.png inside images folder inside your theme MyTheme.

You can try the following:


implement hook_preprocess_HOOK




/**
 2. Implements hook_preprocess_HOOK().
 */
function extended_url_preprocess_paragraph(&$variables) {
  $variables['theme_path'] = drupal_get_path('theme', 'MyTheme');
}




In your twig you can do something like:


{% if content.field_image|render = true %}  
    {{ content.field_image }}  
{% else %}  
&lt;img src="{{ theme_path ~ directory }}/images/default_img.png"/&gt;
{% endif %}