jenssegers / blade Goto Github PK
View Code? Open in Web Editor NEW🔪 A standalone version of Laravel's Blade templating engine for use outside of Laravel.
Home Page: https://jenssegers.com
🔪 A standalone version of Laravel's Blade templating engine for use outside of Laravel.
Home Page: https://jenssegers.com
Please release the new version
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
$blade->share($key, $value) does not work. What should I do for it ?
is it possible to use custom blade Blade::directive() , if yes, will you give me an example??
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?
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)
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.
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.
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?
Hi!
make() echos the view immediately, I want to add the generated view to a response.. is that possible? if so - please tell me how :)
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..
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.
I put together a demo using this package that allows using the x-component tag syntax in template files.
https://github.com/clickfwd/blade-standalone-component-tags
Would love some feedback on whether this is a good approach or if someone has a better way to do it.
It can't Analytic variable using {{ $car }}, but it can Analytic variable by origin php quote like "
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
I can't use on CI 3. How can I fix this issue ?
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
如这里所说: http://stackoverflow.com/questions/27956821/can-i-use-dbtabletags-outside-of-laravel
网上有很多教程移植 Eloquent , 并且可以使用成功, 如移植到 codeigniter 中, 可以直接使用 Active Record 用法(User::first());
可是, 如何移植他的基本用法呢 ? 如: DB::table('user')->get();
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.
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;
}
}
}
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 ?
In Laravel 7.x, after calling $blade->make
, any usage of the Storage facade generates the error "Target class [filesystem] does not exist".
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 ?
Any chance of issuing a new release with the updated illuminate/view
version in the master branch?
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
Hi can i use Localization with this ?
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?
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?
New syntax:
@component, @slot
@verbatim
$loop variable
@stack
... etc ...
More info: https://laravel.com/docs/5.5/blade
Sorry, this may be a newbie question, but, is there a way to use compileString
here?
@bobthecow/mustache supports the following:
$mustache_options = array('extension' => '.html');
I'd like to use .html
, .php
, .whatever
for my filename extensions for this project. Thanks again.
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 ?
illuminate/view (v5.4.0)
Call to undefined method Illuminate\View\Factory::getFirstLoop()
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!
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?
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).
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
Problem - jenssegers/blade v1.2.2 requires illuminate/view ^5.5
Please add a new version illuminate/view ^6.0
Can i use this in Codeigniter 4? If yes, can you give me some examples how integrate to CI 4?
I want to use the @svg directive from blade-icons (https://github.com/blade-ui-kit)
But i don't know how to set this up in this standalone Blade.
Is there a way to make this and adjust the default icon directive so i can use custom icons?
Would be nice to keep up with new versions
Please add support for illuminate/view : 9.0 support?
Can i use this in wordpress? If yes, can you give me some examples how integrate to wordpress?
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!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.