drupal 8 how to print any custom variable in twig

  • Theme name : atvdirect
    create a file atvdirect.theme on root of your theme where atvdirect.info.yml file is places.

    • add below code in atvdirect.theme file
<?php
function atvdirect_preprocess_page(&$variables) {
  $variables['logopath'] = '/' . drupal_get_path('theme','atvdirect') . '/logo.png';
}
?>

now you can use {{ logopath }} in page.html.twig