twig - Using Twigbridge in a Laravel 5.1 Package -
i'm trying create laravel 5.1 package uses twigbridge
instead of .php
views. can normal .php
views display fine, when try make use of .twig
templates i'm met error. possible use twigbridge templates when creating views laravel package or pretty stuck blade
, php
?
edit 1: loading twig template without extending works. it's when start using {% extends 'file' %}
error comes out.
i error
error loading /virtual/laravel/packages/username/mypackage/src/views/sample.twig: template "templates.master" not defined () in "/virtual/laravel/packages/username/mypackage/src/views/sample.twig" @ line 1.
my folders
username |_ mypackage |_ src |_ controllers - samplecontroller.php |_ views |_ templates - master.twig - sample.twig
twig template sample.twig
{% extends 'templates.master' %} {% block content %} {{ parent() }} {% endblock %}
my templates/master.twig file has {% block content %} hello world {% endblock %}
in it.
my composer.json
{ "name": "username/mypackage", "description": "", "license": "mit", "keywords": ["laravel"], "authors": [ { "name": "username", "email": "username@gmail.com" } ], "require": { "rcrowe/twigbridge": "0.7.x" }, "minimum-stability": "stable" }
my service provider (simplified)
<?php namespace username\mypackage; use illuminate\support\serviceprovider; class mypackageserviceprovider extends serviceprovider { /** * bootstrap application services. * * @return void */ public function boot() { // route include __dir__.'/routes.php'; } /** * register application services. * * @return void */ public function register() { // line works fine normal .php views reason not .twig views $this->loadviewsfrom(__dir__ . '/views', 'mypackage'); // providers $this->app->register('twigbridge\serviceprovider'); // aliases $loader = \illuminate\foundation\aliasloader::getinstance(); $loader->alias('twig', 'twigbridge\facade\twig'); $this->app['mypackage'] = $this->app->share(function($app) { return new mypackage; }); } /** * register view file namespace. * * @param string $namespace * @param string $path * @return void */ protected function loadviewsfrom($path, $namespace) { if (is_dir($apppath = $this->app->basepath().'/resources/views/vendor/'.$namespace)) { $this->app['view']->addnamespace($namespace, $apppath); } $this->app['view']->addnamespace($namespace, $path); } /* */ }
controller pretty basic
<?php namespace username\mypackage\controllers; use app\http\controllers\controller; class samplecontroller extends controller { public function sample() { return view('mypackage::sample'); } }
sorry answer own question, found out answer reference package. {% extends 'folder.file' %}
becomes {% extends 'packagename::folder/file' %}
.
that loads file not answer how functions {{ form_text() }}
work. since i'm using rcrowe/twigbridge
there way functions work?
Comments
Post a Comment