Support the ongoing development of Laravel.io →
Views Blade Packages
Last updated 2 years ago.
0

Somebody ?

Last updated 2 years ago.
0

I haven't done it personally, but maybe. Make a composer.json and add in the laravel view as a package and see what happens.

This lists out the other required packages, https://packagist.org/packages/illuminate/view

Last updated 2 years ago.
0

I already done that but now I need to use the view class from laravel. Only problem is that I don't know which namespace and class I need to use ( so i dont need any heavy configuration ),

I will try again tomorrow, but i hope someone can help me, Because all tuts are about the laravel blade package which is not supported in my project because the dependencies are lower than what i have now.

Sorry for my poor spelling.

Last updated 2 years ago.
0

Can someone help me please here is the code I have now,

public function loadBlade($view, $viewPath = false, $data = array() ) {
		
		echo $this->viewPath;
		if(isset($viewPath)) {
		
			$this->viewPath = $viewPath;
		}
		
		$FileViewFinder = new FileViewFinder(
			new Filesystem,
			$this->viewPath
		);
		
		$PhpEngine = new PhpEngine();
		$PhpEngine->get($this->viewPath, $data);
		
		$dispatcher = new Dispatcher(new Container);

		$factory = new Factory(
			new EngineResolver, 
			$FileViewFinder,
			$dispatcher
		);

		$view = new View(
			$factory,
			$PhpEngine,
			$view,
			$this->viewPath,
			$data
		);

		return $factory;

    }

And I get this error : Fatal error: Uncaught exception 'InvalidArgumentException' with message 'View [hello.php] not found.' in /system/vendor/illuminate/view/FileViewFinder.php:146 Stack trace: #:0 /system/vendor/illuminate/view/FileViewFinder.php(83): Illuminate\View\FileViewFinder->findInPaths('hello.php', Array) #:1 /system/vendor/illuminate/view/Factory.php(125): Illuminate\View\FileViewFinder->find('hello.php') #:2 /application/controllers/home.controller.php(27): Illuminate\View\Factory->make('hello.php', 'application/vie...') #:3 [internal function]: Home->index(Array) #:4 /test/Bootstrap.php(42): call_user_func_array(Array, Array) #:5 /test/index.php(53): include('/customers/2/e/...') #:6 {main} thrown in /system/vendor/illuminate/view/FileViewFinder.php on line 146

Last updated 2 years ago.
0

Ok, here goes...

I started with the following directory structure.

Code\standalone-blade-test
Code\standalone-blade-test\app
Code\standalone-blade-test\app\storage\views *(make writeable to www user)
Code\standalone-blade-test\app\views
Code\standalone-blade-test\public

I create the following composer.json in the app directory,

{
	"name": "wpb/standalone-blade-test",
	"description": "standalone blade test",
	"keywords": ["framework", "laravel"],
	"license": "MIT",
	"type": "project",
	"require": {
		"illuminate/view": "4.2.*@dev"
	},
	"require-dev": {
		 
	},
	"autoload": {
		"classmap": [],
		"psr-4": {
			"App\\": "app/"
		}
	},
	"scripts": {
		 
	},
	"config": {
		"preferred-install": "dist"
	},
	"minimum-stability": "dev"
}

Not all of that is likely required, I just copied an existing and changed the required section, etc.

Next, ran composer update in the app dir... it created a vendor and downloaded stuff...

Here is the simple test blade template located in the app\views\test.blade.php

<h1>This is a test template<h1>

<b>Var value is - {{ $testvar }}</b>

Here is the test class file,

<?php

// include the autoloader
require __DIR__.'/../app/vendor/autoload.php';
Illuminate\Support\ClassLoader::register();

// create test class
$n = new testClass();
$n->testme();

// the required libs
use Illuminate\View\FileViewFinder;
use Illuminate\Filesystem\Filesystem as Filesystem;
use Illuminate\View\Compilers\BladeCompiler;
use Illuminate\View\Engines\CompilerEngine;
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container as Container;
use Illuminate\View\Factory;
use Illuminate\View\Engines\EngineResolver;
use Illuminate\View\View as View;

class testClass {

    function testme() {

        // create a template
        $r = $this->loadBlade('not-sure-what-this-does', __DIR__.'/../app/views/test.blade.php', array('testvar' => ' timestamp: '.time()) );
        // render the template
        echo $r->render();
    }

    function loadBlade($view, $viewPath = false, $data = array() ) {

           // echo $this->viewPath;
            if(isset($viewPath)) {
                $this->viewPath = $viewPath;
            }

            // this path needs to be array
            $FileViewFinder = new FileViewFinder(
                new Filesystem,
                array($this->viewPath)
            );

            // use blade instead of phpengine
            // pass in filesystem object and cache path
            $compiler = new BladeCompiler(new Filesystem(), __DIR__.'/../app/storage/views');
            $BladeEngine = new CompilerEngine($compiler);

            // create a dispatcher
            $dispatcher = new Dispatcher(new Container);

            // build the factory
            $factory = new Factory(
                new EngineResolver,
                $FileViewFinder,
                $dispatcher
            );

            // this path needs to be string
            $viewObj = new View(
                $factory,
                $BladeEngine,
                $view,
                $this->viewPath,
                $data
            );

            return $viewObj;

        }
}

I only spend about 2 hours getting it to work so it is not tested a lot, but appears to be working.

Hope that helps :)

Last updated 2 years ago.
0

You are awesome I really want to thank you so much ! Spend hours looking myself but I got only this far.

You are my hero ! Gonna credit you in the code because you are awesome.

Thank you very much.

Last updated 2 years ago.
0

You welcome and thanks for the in code credit reference. :)

I was also trying to get my StringBladeCompiler to work with this code, but other things took over my day.

If you need to, or want to, use a string template instead of a blade template file it might be something to check out. Will need to roll back the update to support Laravel 5-dev, but its only a couple lines.

https://github.com/TerrePorter/StringBladeCompiler

Last updated 2 years ago.
0

Just copied and edited some of the code to match my server. But got the same error again which is strange because I only changed to directories to the right ones. Don't know if you use cloud9 but if you would, you can view.

Last updated 2 years ago.
0

Humm...

I have the free account version on cloud9 now, looks interesting.

Last updated 2 years ago.
0

Hello terre, Here is the link to the workspace : c9 project

-- Note : Got it working finaly, now I also know what I need to edit.

Last updated 2 years ago.
0

Awesome! Glad you got it working. The c9 editor looks nice, I'll have to check it out some more later.

I wasn't sure where I could work in some time to take a look, my schedule for today is looking a bit busy. :)

Last updated 2 years ago.
0

Hi,

I have a small example I just did if it can help anyone: https://github.com/DODMax/blade_standalone_example

Cheers!

0

I there

Its for the record (since i know that its a bit old thread) but its one of the first one that show me google:

A couple of days ago i checked this thread (amongs many threads. i was searching for the best template engine for php) and i found about the alternatives to use Blade outside Laravel. However, most alternatives are HUGE with lots of files and even some of them with dependencies and frankly, i don't like to bloat my code.

I checked the code of Blade and i found that Blade is quite simple so i decided to creates a version of Blade that use a single file and a single class.

BladeOne (MIT license, feel free to usage)

Its quite compatible with Blade (unless you are using extensions or hacks).

I am not tested yet but i bet that its also compatible with Laravel. It requires to add 3 lines, the include, creates the object and call it. No namespace or other dependencies.

And the best, adding extensions is really simple, it doesn't even requires a regular expression. I already added a couple of extensions by (ahem) extending the class.

Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

domeinznl domeinznl Joined 7 Sep 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.