How to get path of image from file id I have this output from my twig template dump:

/var/www/html/vendor/twig/twig/lib/Twig/Extension/Debug.php:56:
array (size=7)
  'id' =&gt; string 'views_block:about-block_1' (length=25)
  'label' =&gt; string '' (length=0)
  'provider' =&gt; string 'views' (length=5)
  'label_display' =&gt; string '0' (length=1)
  'views_label' =&gt; string '' (length=0)
  'items_per_page' =&gt; string '3' (length=1)
  'background' =&gt; 
    array (size=1)
      0 =&gt; string '136' (length=3)


So my file id (fid) is 136. I'd like to know a way to get this file's url without having to use a preprocess function.

Can this be done? Would I have to do a custom twig function to achieve this? If so where would I add the code to extend twig?

ex:

$twig = new Twig_Environment($loader);
$function = new Twig_SimpleFunction('function_name', function () {
    // ...
});
$twig-&gt;addFunction($function);
So I decided to create a module to extend twig and get the file url from its fid. 

get_url_from_fid git project

Source of src/GetUrlFromFid.php

&lt;?php
namespace Drupal\get_url_from_fid;

class GetUrlFromFid extends \Twig_Extension{

  /**
   * {@inheritdoc}
   * This function must return the name of the extension. It must be unique.
   */
  public function getName(){
    return 'get_url_from_fid';
  }

  /**
   * In this function we can declare the extension function
   */
  public function getFunctions(){
    return array(
      new \Twig_SimpleFunction('get_url_from_fid',
        array($this, 'get_url_from_fid'),
        array('is_safe' =&gt; array('html'))
      )
    );
  }

  public function get_url_from_fid($fid){
    $file = \Drupal\file\Entity\File::load($fid);
    if(!is_null($file)){
      $uri = $file-&gt;getFileUri();
      return file_create_url($uri);
    }else{
      return false;
    }
  }
}