Giter Site home page Giter Site logo

jenssegers / blade Goto Github PK

View Code? Open in Web Editor NEW
772.0 772.0 119.0 43 KB

🔪 A standalone version of Laravel's Blade templating engine for use outside of Laravel.

Home Page: https://jenssegers.com

PHP 73.33% HTML 12.05% Blade 14.62%
blade laravel template-engine view

blade's People

Contributors

amoutonbrady avatar daison12006013 avatar edgarsn avatar ionbazan avatar jenssegers avatar lesichkovm avatar peter279k avatar tullaris avatar yuhengliang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blade's Issues

CUSTOM Directive Does NOT Work WITH PHP

When I run this code the custom directive does NOT rendered successfully

require_once dirname(__FILE__, 3) . '/vendor/autoload.php';

use Jenssegers\Blade\Blade;

$viewFolderPath = dirname(__FILE__, 3) . '/app/Blade/views';

$blade = new Blade($viewFolderPath, 'cache');

echo $blade->directive('php', function () {
    return "<?php echo 'Welcome; ?>'";
});

and inside home.blade.php

@php

BUT the output be @php NOT Welcome as expected

Disable Blade caching completly

Hey, thanks for this package.

I've integrated this package with Slim microframework and it works just fine, however, I used the blade directive function to generate in each request a new CSRF token to be embedded in HTML forms to verify each request, the problem is that with the cache blade enabled I got the same CSRF token in each request.

Does this mean the blade does not detect changes in values returned with the directive function ? or I've missed something?

Deleted cache files by accident

Hello there
I accidentally deleted the files in my cache folder and now route won't run.

Illuminate \ View \ ViewException (E_ERROR)
File does not exist at path /home/kaloy/sites/ecommerce/app/Functions/../../bootstrap/cache/f88c6d92e662aedc683ca0761ed8f4d0d9456e54.php. (View: /home/kaloy/sites/ecommerce/resources/views/errors/404.blade.php)

Works with "illuminate/view": "5.0" for v 1.0.0

We are using this package (Thank you) on a php 5.4 server. Unfortunately we are unable to load it in composer because of the "illuminate/view": "^5.1" requirement.

For PHP 5.4 we need to use "illuminate/view": "5.0".

When using your v1.0.0 package outside of composer, everything works as it should.
I was wondering if you would be willing to reduce the dependency for v1.0.0 to "illuminate/view": "5.0".

Thank you.

Semantic versioning please

How in the world did I go from illuminate/view v5 to v8 with a simple composer update?

My components suddenly don't work.

Meanwhile, this package went from 1.2 to 1.4 as if nothing's changed.

Linting blade

I'm looking a way to lint my blade templates. Check for trailing white spaces, correct indentation, unique ID for html elements. I found a tool that is close to this request https://github.com/htmllint/htmllint but it doesn't nativly handle blade templates.

Is there a way to lint blade?

How to Minify output

Laravel Blade: how to minify HTML/CSS/JS if i use your library??
any help will be great for me.

i have found a repository to use partials within blade template, will you give me any suggestion how can i use it with your library.

Repository Link: https://github.com/crhayes/blade-partials

Thanks in advance..

Installation

I pulled this in via composer then added this to my index.php file

<?php
/*
|--------------------------------------------------------------------------
| Register The Auto Loader For Blade 
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the
| loading of any our classes "manually". Feels great to relax.
|
*/

require 'vendor/autoload.php';

use Jenssegers\Blade\Blade;

$views = __DIR__ . 'app/views';
$cache = __DIR__ . 'app/cache';

$blade = new Blade($views, $cache);    ?>

Then I made a home.blade.php file and a layout.blade.php file in my "app/views" directory. My home.blade.php just displays this in the browser

@extends('layout') @section('content')

Some content

@stop

It doesnt render anything. I am familiar with blade inside Laravel but it doesnt seem to be working in this project.

issue install

hi guys,

I have issues when install below image, how to fix?

image

Updated laravel 5.6

Updated illuminate/http to 5.6 it changed the behavior of double encode HTML
If you would like to maintain the previous behavior of preventing double encoding, you may use the

after
$blade = new Blade('views', 'cache');

add line
$blade->compiler()->withoutDoubleEncoding();

Information not to seek a solution to the problem

update packagist

I'm using this package with laravel 5 and wanted to try with 7. I saw you updated package.json to support version 7 on github, but not on packagist yet. Please do it, so I can use your package from composer.
Thanks

how to put coding in this blade file top?

i use @stack and @Push in my blade file.but it not works,because @stack works in layout blade,it not works in a section blade

@stack('test-section')

this is test section

@push('test-section')
    this is test put
@endpush

i just want to make a section have default data,for example

@extends('body')
@section('content')
@stack('test-section')

this is test section{{$top}}

@endsection

@push('test-section')
    this is test put
    @php
        $top = $top??'this top';
    @endphp
@endpush

$top is ok when $top declared in this blade top.my idea from shopify's liquid {% schema %}

it's not necessary ,the section data need declared in the section top,if i declared in the section top,code will become poorly managed

@extends('body')
@section('content')
    @php
        $top = $top??'this top';
        $top1 = $top??'this top';
        $top2 = $top??'this top';
        $top3 = $top??'this top';
        $top3 = $top??'this top';
        $top4 = $top??'this top';
        $top5 = $top??'this top';
        $top6 = $top??'this top';
        $top7 = $top??'this top';
        ...
    @endphp

    this is test section{{$top}}

@endsection

I need help.Thank you very much.

A facade root has not been set

I need to be able to refresh the cache as we are having issues with old content being displayed in the browser after changes have been made and the page has been refreshed. I am aware of the Artisan::call('cache:clear') command. When I run this I get the error 'A facade root has not been set'

<?php

namespace App\Classes;

use Illuminate\Support\Facades\Artisan;
use Jenssegers\Blade\Blade as B; // the actual blade templating engine plugin

class Blade
{
/**
* Needs to be included in every controller method where a view is included. sets blade plugin and template vars.
* @param $view
* @param $data
* @param $run - will run or return template if true
* @param $clearCache
*/
public static function run($view, $data, $run = true, $clearCache=false){
try{
// $blade = new B(BEDROCK_ROOT.'includes/v2/resources/views', BEDROCK_ROOT.'includes/v2/resources/cache');
$blade = new B(BEDROCK_ROOT.'includes/v2/resources/views', BEDROCK_ROOT.'includes/v2/resources/cache');
if($clearCache){
Artisan::call('clear:cache');
}
if($run){
echo $blade->make($view, $data);
exit;
} else {
return $blade->make($view, $data);
}

    } catch (\Exception $e){
        echo $e->getMessage();
        die;
    }
}

}

Cache refreshing ?

Hi,

When I update a view I don't see the modifications reflected in the browser.

I configure the php directive opcache.revalidate_freq=0. The file timestamp is correctly modified on the machine.

The only way to see the modifications is to manually clear the cache folder in the project.

Anybody knows a workaround for this ?

How to know if is using template cache ?

I use this package in a codeigniter 4 project, everything work seems ok, but how can i know codeigniter is using template cache or every time it will go through controller ?

New release?

Any chance of issuing a new release with the updated illuminate/view version in the master branch?

Why we should echo instead of return?

Hi,

Could you please describe why we should do
echo $blade->make('homepage', ['name' => 'John Doe']);
instead of doing
return $blade->make('homepage', ['name' => 'John Doe']);?

Thanks

Question about blade in blade usage

I have a blade file for a page (in a folder called /views/pages), and I would like to include a other blade file (directly in folder /views) to render a tablecontents. Is this possible, how can I include a tablecontents-component in a blade-page?

Registering a global variable?

When using Laravel, registering a global variable would be done via a service provider, but I'm currently unsure on how to do this with your standalone version.

I've got a View class:

class View {

	/**
	 * Render a view template with blade
	 *
	 * @param  string  $template  The template file to render
	 * @param  array   $data      The data passed to the view
	 * @return void
	 */

		public static function create($template, $data = []) {

			// Set view and cache directories
				$views = dirname(__DIR__) . '/views';
				$cache = dirname(__DIR__) . '/cache';

			// Create a new instance of blade
				$blade = new Blade($views, $cache);

			// Call the make function to display the template
				echo $blade->make($template, $data);

		}

}

I know I can pass data from a controller like this:

View::create('path.to.template', [
	'name' => $name,
]);

But I'm currently wanting to pass the $_SESSION variable so all the templates have access to it. I don't really want to have to pass it through individually every time and I'm guessing there is a way to register a global variable but I'm afraid I can't see how to do it. Is it possible?

Locating parse error

When an error is encountered in the .blade.php file the following output is thrown :

Fatal error: Method Illuminate\View\View::__toString() must not throw an exception, caught ErrorException: ... in C:\htdocs\project\file.php on line 0

It always points to line 0. Any way to get the line in the blade.php where the error occurs ?

Added support for illuminate/view ^9.0

Is there a ETA for adding support?
I create a PR for this purpose, but if that was not correct, is there a ETA for adding this?

Does the package have active support?

Thanks!

Update from 1.1.0 to 1.2.1 breaks $blade->share()

I just updated from 1.1.0 to 1.2.1, and $view->blade() no longer works.

In my middlware
// this line actually is defined in the initialization portion of my app, and is then stored in a service container. In my middleware, I grab the $blade object from the container, and call share(), and then later, in my controller, I get the $blade object from the container once again, and call make()
$blade = new Blade($config['app']['template-views'], $config['app']['template-cache']);
// hash is not empty, it is an array
$blade->share('categoryHash', $hash);

In my view:
echo (bool) is_null($categoryHash); die();

And the output is 1 (or true), indicating the value is null, when it should contain an array

This works fine in <= 1.1.0, but breaks when I updated to 1.2.1. Am I missing something?

Compatibility with PHP 5.6.* versions

Is there any change to use sandalone-version of Blade with PHP 5.6.* versions?

As it seems for now, it hardly requires php ^7.1.3 (in dependencies).

define root

How to define a root for Blade() so you can use it in any folders with out its believe that views are located in the same folder

Upgrade to Blade 6.0

Problem - jenssegers/blade v1.2.2 requires illuminate/view ^5.5

Please add a new version illuminate/view ^6.0

Can use in Codeigniter 4

Can i use this in Codeigniter 4? If yes, can you give me some examples how integrate to CI 4?

Can use in Wordpress?

Can i use this in wordpress? If yes, can you give me some examples how integrate to wordpress?

Register Current as a Release

I ran into an issue where composer require jenssegers/blade set it up to the ^1.0 version in my composer.json. This isn't the newest stuff available, and I was missing out on the super nice addition of the compiler()->directive stuff (in dev-master).

Registering a new release in github could save others a headache I think.

Thanks for the tool!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.