0

I'm new at Symfony and Twig. I've got a problem with Twig.

I always got the following error

Unable to find template "BackendBackofficeBundle::base.html.twig" (looked into: C:\Users\Username\Documents\NetBeansProjects\idno_backoffice\app/Resources/views, C:\Users\Username\Documents\NetBeansProjects\idno_backoffice\vendor\symfony\symfony\src\Symfony\Bridge\Twig/Resources/views/Form) in @BackendBackoffice\consultant\index.html.twig at line 1.

My index.html.twig looks like

{% extends 'BackendBackofficeBundle::base.html.twig' %}
{% block body %}
<div class="row">           
    <div class="col-md-12">
        <div class="panel panel-default">
            <div class="panel-heading">Search .../<div>
                <div class="panel-body">
                <div class="input-group">
                    <input type="text" class="form-control">
                    <div class="input-group-btn">
                        <button class="btn btn-default" type="button">Go!</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="row">           
    <div class="col-md-12">
        <div class="panel panel-default">
            <div class="panel-heading">Overview</div>
            <div class="panel-body">
                <p>No Tickets</p>
            </div>
            <table class="table">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>Subject</th>
                        <th>Customer</th>
                        <th>Created_at</th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>
</div>
{% endblock %}

My base.html.twig looks like

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset={{ _charset }}"/>
    <meta name="robots" content="noindex,nofollow"/>
    <title>{% block title %}Backoffice{% endblock %}</title>
    <link rel="stylesheet" href="{{ asset('bundles/backendbackoffice/bootstrap/css/bootstrap.min.css') }}"/>
    <link rel="stylesheet" href="{{ asset('bundles/backendbackoffice/bootstrap/css/bootstrap-theme.min.css') }}"/>
    <link rel="stylesheet" href="{{ asset('bundles/backendbackoffice/backoffice/css/main.css') }}"/>
    {% block head %}{% endblock %}
</head>
<body role="document">

    <!-- navbar -->
    <nav class="navbar navbar-default">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed"
                        data-toggle="collapse" data-target="#menu-toggle">
                    <span class="sr-only"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="/">Test 1</a>
            </div>

            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="menu-toggle">
                <ul class="nav navbar-nav">
                    <li><a href="#">Overview</a></li>
                </ul>
            </div>
            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container-fluid -->
    </nav>
    <!-- /navbar -->

    <div class='container'>
        {% block body %}{% endblock %}
    </div>

    {% block javascripts %}
        <script src="//code.jquery.com/jquery-1.9.1.min.js"></script>
        <script src="{{ asset('bundles/backendbackoffice/bootstrap/js/bootstrap.min.js') }}" type="text/javascript"></script>
    {% endblock %}

</body>

</html>

Can anyone help me? I don't know why my index.html.twig can't find my base.html.twig.

If u need some more files pls tell me.

Premox
  • 323
  • 10
  • 25
  • Did you make sure it's in the correct directory so Twig can find it? – Rimble Nov 08 '18 at 12:49
  • 1
    Symfony version? Probably related to [this](https://stackoverflow.com/questions/47832977/symfony-3-4-use-view-inside-my-bundle/47835716#47835716). – Cerad Nov 08 '18 at 12:56
  • 1
    @Rimble: I removed at my `index.html.twig` the namespace `BackendBackofficeBundle::` and it works. I thought I had to tell him the Bundle namespace which base file I mean – Premox Nov 08 '18 at 12:58
  • @Cerad: That was my problem. I'm using Symfony 3.4 – Premox Nov 08 '18 at 13:01
  • Glad you got it working. Feel free to upvote the linked answer. – Cerad Nov 08 '18 at 13:08
  • @Cerad: I understood the first mistake of myself with the DocumentRoot. But at the moment If I enter at my URL `/addConsultant` I got another error `Unable to find template "BackendBackofficeBundle:Consultant:add_consultant" (looked into: C:\Users\Username\Documents\NetBeansProjects\idno_backoffice\app/Resources/views, C:\Users\Username\Documents\NetBeansProjects\idno_backoffice\vendor\symfony\symfony\src\Symfony\Bridge\Twig/Resources/views/Form)`. He's at the correct Action function – Premox Nov 08 '18 at 13:23
  • @Cerad: Got it again. My controller returns `return $this->render('BackendBackofficeBundle:Consultant:add_consultant.html.twig', array( // ... ));`. I replaced the return statement with an empty array and it works. The same mistake as the first error? – Premox Nov 08 '18 at 13:25

1 Answers1

1

If you are using symfony 3.4 you should include config/config.yml

framework:
    templating:
        engines: ['twig']

after that run

composer install

somesh
  • 528
  • 2
  • 10
  • 26