Need help with twig test template I'm trying to create a test twig template in drupal 8, I followed "Create custom twig templates for custom module" from their website but it's not working for me for some reason. This is what I have:

Contents of folder test_twig_template:

test_twig_template.info.yml:

name: Test Twig Theme
type: module
description: Module to test if twig theme is working as intended
package: Custom
version: 1.0.0
core: 8.x


test_twig_template.module:

&lt;?php
function test_twig_template_theme($existing, $type, $theme, $path) {
  return [
    'my_template' =&gt; [
      'variables' =&gt; ['test_var' =&gt; NULL],
    ],
  ];
}


test_twig_template.routing.yml:

test_twig_template.theme:
      path: /twig
      defaults:
        _controller: Drupal\test_twig_template\Controller\TestTwigTemplateController::content
        _title: 'Twig title'
      requirements:
        _permission: 'access content'


Code inside test_twig_template/src/Controller/TestTwigTemplateController.php:

&lt;?php
namespace Drupal\test_twig_template\Controller;
use Drupal\Core\Controller\ControllerBase;

class TestTwigTemplateController extends ControllerBase {
  public function content() {
    return array(
      '#title' =&gt; 'Test Twig title',
      '#theme' =&gt; 'my_template',
      '#test_var' =&gt; $this-&gt;t('Test Value'),
    );
  }
}


And finally inside test_twig_template/templates/my-template.html.twig I have:

  &lt;p&gt;Test twig template!&lt;/p&gt;
  &lt;p&gt;test_var: {{ test_var }}&lt;/p&gt;


Thing is if I remove this "'#title' => 'Test Twig title'," from my controller nothing gets displayed on my custom page. Otherwise it just displays this title "Test Twig title". 
Am I missing a call for twig somewhere or are my hooks_theme() not properly set up?
It looks like you are messing around with your naming.

Since your module is called test_twig_template you must use that name for hooks and namespaces etc.

Fix these things and it should work.


  
  Rename your hook_theme() from test_twig_theme to test_twig_template_theme.
  Call your route test_twig_template.theme.
  Your controller definition in your route must look like this, _controller: \Drupal\test_twig_template\Controller\TestTwigThemeController::content.
  The namespace in your controller must be namespace Drupal\test_twig_template\Controller;.
  Rename test_twig_template/src/Controller/TestTwigController.php to test_twig_template/src/Controller/TestTwigThemeController.php (the file name must match the class name).
  


That should be all, since your module is called test_twig_template it's important to use that name in all namespaces for your code to work properly :)

And then as @Hudri mentions your template shall only contain:

&lt;p&gt;Test twig template!&lt;/p&gt;
&lt;p&gt;test_var: {{ test_var }}&lt;/p&gt;


Head and body tags are provided by a general template in your theme.