mrjayviper mrjayviper - 5 months ago 42
Twig Question

cannot load Twig template (Symfony 2.8.8)

So I have the folder structure below:

enter image description here

According to the Symfony manual (click here), I should be able to load my Twig template but Symfony cannot find it.

enter image description here

Any ideas what I could be doing wrong? Thank you.

codes I've tried

return $this->render(
, array(
"form" => $form->createView()

return $this->render(
, array(
"form" => $form->createView()

Contents of my app/AppKernel.php


use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
public function registerBundles()
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new AppBundle\AppBundle(),

new Symfony\Bundle\AsseticBundle\AsseticBundle(),

if (in_array($this->getEnvironment(), array('dev', 'test'), true)) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();

return $bundles;

public function registerContainerConfiguration(LoaderInterface $loader)

contents of app/config/config.yml

- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }

# Put parameters here that don't need to change on each machine where the app is deployed
locale: en

#esi: ~
#translator: { fallbacks: ["%locale%"] }
secret: "%secret%"
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
engines: ['twig']
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true

# Twig Configuration
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"

# Doctrine Configuration
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"

auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true

# Swiftmailer Configuration
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }

debug: '%kernel.debug%'
use_controller: '%kernel.debug%'
cssrewrite: ~


Because you are storing the template inside the bundle, you also have to reference the directory within the views - in this case, a 'null' directory.


Note the :: for the directory.

If you moved the entire AppBundle/Resources/views/ directory to app/Resources/views/ then you would be able to reference them much as a plain subdirectory:

Referencing templates stored in:

app/Resources/views/           | AcmeDemoBundle/Resources/views
 ----------------------------- | ------------------------------- 
index.html.twig                | AcmeDemoBundle::index.html.twig
Default/subdir/index.html.twig | AcmeDemoBundle:Default:subdir/index.html.twig
Default/subdir/index.html.twig | AcmeDemoBundle:Default/subdir:index.html.twig