How to use variable value in twig file? I have below code in:

{% set img_url = item.image.url ? item.image.url : {{ base_path ~ directory }}'/images/default.png' %}


Twig file. How to make it work so it will take full default image path?
To get the base_url (path) you will need this in your THEMENAME.theme file 

function THEMENAME_preprocess_page(&amp;$variables) {
  global $base_url;
  $variables['base_path'] = $base_url;
}


Then it will be available in your twig template

But most of the times you will not need the full path to display an image 

You can try the following

{% set img_url = item.image.url ? item.image.url : '/'{{ directory }}'/images/default.png' %}