title: Using Twigbridge in a Laravel 5.1 Package
body: <p>I'm trying to create a Laravel 5.1 package which uses <code>Twigbridge</code> instead of <code>.php</code> views. I can get normal <code>.php</code> views to display fine, but when I try to make use of <code>.twig</code> templates I'm only met with an error. Is it possible to use Twigbridge templates when creating views for a Laravel Package or we pretty much stuck with <code>blade</code> and <code>php</code>?</p>
  
  <p><strong>Edit 1:</strong> Loading a Twig template without extending anything works. It's when I start using <code>{% extends 'file' %}</code> that the error comes out.</p>
  
  <p>I get this error</p>
  
  <pre><code>Error loading /virtual/laravel/packages/username/mypackage/src/Views/sample.twig:
  Template "templates.master" is not defined () in
  "/virtual/laravel/packages/username/mypackage/src/Views/sample.twig" at line 1.
  </code></pre>
  
  <p>My folders</p>
  
  <pre><code>username
      |_ mypackage
          |_ src
              |_ Controllers
                  - SampleController.php
              |_ Views
                  |_ templates
                          - master.twig
                  - sample.twig
  </code></pre>
  
  <p>Twig template <em>sample.twig</em></p>
  
  <pre><code>{% extends 'templates.master' %}
  
  {% block content %}
      {{ parent() }}
  {% endblock %}
  </code></pre>
  
  <p>My <em>templates/master.twig</em> file has <code>{% block content %} Hello World {% endblock %}</code> in it.</p>
  
  <p>My <em>composer.json</em></p>
  
  <pre><code>{
      "name": "username/mypackage",
      "description": "",
      "license": "MIT",
      "keywords": ["laravel"],
      "authors": [
          {
              "name": "username",
              "email": "username@gmail.com"
          }
      ],
      "require": {
          "rcrowe/twigbridge": "0.7.x"
      },
      "minimum-stability": "stable"
  }
  </code></pre>
  
  <p>My Service Provider (simplified)</p>
  
  <pre><code>&lt;?php namespace Username\MyPackage;
  
  use Illuminate\Support\ServiceProvider;
  
  class MyPackageServiceProvider extends ServiceProvider {
  
      /**
       * Bootstrap the application services.
       *
       * @return void
       */
      public function boot()
      {   
          // Route
          include __DIR__.'/routes.php';
      }
  
      /**
       * Register the application services.
       *
       * @return void
       */
      public function register()
      {
          // This line works fine for normal .php views but for some reason not for .twig views
          $this-&gt;loadViewsFrom(__DIR__ . '/Views', 'mypackage');
  
          // Providers
          $this-&gt;app-&gt;register('TwigBridge\ServiceProvider');
  
          // Aliases
          $loader = \Illuminate\Foundation\AliasLoader::getInstance();
          $loader-&gt;alias('Twig', 'TwigBridge\Facade\Twig');
  
          $this-&gt;app['mypackage'] = $this-&gt;app-&gt;share(function($app) {
              return new MyPackage;
          });
      }
  
      /**
      * Register a view file namespace.
      *
      * @param  string  $namespace
      * @param  string  $path
      * @return void
      */
      protected function loadViewsFrom($path, $namespace)  
      {
          if (is_dir($appPath = $this-&gt;app-&gt;basePath().'/resources/views/vendor/'.$namespace)) {
              $this-&gt;app['view']-&gt;addNamespace($namespace, $appPath);
          }
          $this-&gt;app['view']-&gt;addNamespace($namespace, $path);
      }
      /*
      */
  
  }
  </code></pre>
  
  <p>Controller is pretty basic</p>
  
  <pre><code>&lt;?php namespace Username\MyPackage\Controllers;
  
  use App\Http\Controllers\Controller;
  
  class SampleController extends Controller {
  
      public function sample() {
          return view('mypackage::sample');
      }
  
  }
  </code></pre>