robinradic / blade-extensions Goto Github PK
View Code? Open in Web Editor NEWLaravel Blade extensions like $loop->odd/$loop->index in foreach, view blocks and partials, etc
Home Page: http://robin.radic.nl/blade-extensions
License: MIT License
Laravel Blade extensions like $loop->odd/$loop->index in foreach, view blocks and partials, etc
Home Page: http://robin.radic.nl/blade-extensions
License: MIT License
That looks like a promising extension!
The multi line array definition enlightened me that I always wanted a multi line @include
, but in plain blade it is not possible, as far as I know.
So instead of this:
@include('some.route', array('a'=>'bunch','of'=>'parameters','to'=>'pass','on'=>'here','in'=>'only','one'=>'line')
One could use a briefer one:
@include('some.route', array(
'a'=>'bunch',
'of'=>'parameters',
'to'=>'pass',
'on'=>'here',
'but'=>'in',
'multiple'=>'lines')
Please consider this idea, and good work finishing the extension!
When you are using eager loading with eloquent for example and u want to write this:
@foreach($foo->bar as $item)
the extension will pick up $foo instead of $foo->bar
this can be fixed by add '->' to the regex for openForEach function:
line 72 of BladeExtender.php
$matcher = '/@foreach(\s?)\(\$(.[0-9a-zA-Z_\->]+)(\s?)(.*)\)/';
When I want to quickly debug my view, I usually end up using this line of code:
<pre><code>{{ dd($val) }}</code></pre>
If I understand right the current proposal of @debug
, now it would look like this:
<pre><code>
@debug($val)
</code></pre>
Which is still too much to type...
I think in most cases one would need the <code>
and <pre>
tags for a nice output, so please consider including those in @debug
, so it would do the job alone for debugging:
@debug($val)
It is possible to make these variables accessible?
It is pain to write code like this
@embed('components.box', ['offices'=>$offices, 'labels'=>$labels, 'years'=>$years ......] )
Updated composer.json (set blade-extensions to >=6.0)
composer dump-autoload
composer update
did php artisan vendor:publish --provider=Radic\BladeExtensions\BladeExtensionsServiceProvider which gave me nothing to publish for tag []
duplicated the config file blade_extensions.php under "project/config/"
Added into my view at first lines the exemple with @macro('alert')
Thrown me :
Argument 4 passed to Radic\BladeExtensions\Directives\MacroDirectives::directiveMacro() must implement interface Illuminate\Contracts\Foundation\Application, instance of Illuminate\View\Compilers\BladeCompiler given, called in /Applications/AMPPS/www/inMindBO/vendor/radic/blade-extensions/src/Traits/BladeExtenderTrait.php on line 63 and defined
in MacroDirectives.php line 38
at HandleExceptions->handleError('4096', 'Argument 4 passed to Radic\BladeExtensions\Directives\MacroDirectives::directiveMacro() must implement interface Illuminate\Contracts\Foundation\Application, instance of Illuminate\View\Compilers\BladeCompiler given, called in /Applications/AMPPS/www/inMindBO/vendor/radic/blade-extensions/src/Traits/BladeExtenderTrait.php on line 63 and defined', '/Applications/AMPPS/www/inMindBO/vendor/radic/blade-extensions/src/Directives/MacroDirectives.php', '38', array('value' => '@macrodef('alert') ', 'pattern' => false, 'replacement' => object(Application))) in MacroDirectives.php line 38
at MacroDirectives->directiveMacro('@macrodef('alert') ', false, object(Application), object(BladeCompiler)) in BladeExtenderTrait.php line 63
at MacroDirectives::Radic\BladeExtensions\Traits{closure}('@macrodef('alert') ', object(BladeCompiler))
at call_user_func(object(Closure), '@macrodef('alert') ', object(BladeCompiler)) in BladeCompiler.php line 185
at BladeCompiler->compileExtensions('@macrodef('alert') ') in BladeCompiler.php line 169
at BladeCompiler->parseToken(array('314', '@macrodef('alert') ', '1')) in BladeCompiler.php line 143
Is there anyways to make minification at view's compile time? I tried to use https://github.com/GrahamCampbell/Laravel-HTMLMin package to minify views at compile time but it breaks extensions from this package
Hi,
I would ask why the package doesn't work for the @minify
.
The example:
<script>
@minify('js')
var exampleJavascript = {
this: 'that',
foo: 'bar',
doit: function(){
console.log('yesss');
}
};
@endminify
</script>
After compiled stays the same.
$loop->parentLoop
should just be
$loop->parent
Unfortunately, thie extension is not working anymore under laravel 5.*. Is an update planned?
After Update to Laravel 5.1 and blade-extensions, I got errors
FatalErrorException in DebugDirectives.php line 37:
Call to undefined method Illuminate\View\Compilers\BladeCompiler::createPlainMatcher()
in DebugDirectives.php line 37
at FatalErrorException->__construct('message' => ''Call to undefined method Illuminate\View\Compilers\BladeCompiler::createPlainMatcher()'', 'code' => '1', 'severity' => '0', 'filename' => ''D:\dev\project\vendor\radic\blade-extensions\src\Directives\DebugDirectives.php'', 'lineno' => '37', 'traceOffset' => '0', 'traceArgs' => '') in HandleExceptions.php line 127
at HandleExceptions->fatalExceptionFromError('error' => 'array ('type' => 1, 'message' => 'Call to undefined method Illuminate\View\Compilers\BladeCompiler::createPlainMatcher()', 'file' => 'D:\dev\project\vendor\radic\blade-extensions\src\Directives\DebugDirectives.php', 'line' => 37)', 'traceOffset' => '0') in HandleExceptions.php line 112
at HandleExceptions->handleShutdown() in HandleExceptions.php line 0
at DebugDirectives->addBreakpoint('value' => ''<div clas.....
Hi,
It looks like the following code doesn't work as expected.
<form method="@render('formMethod', 'POST')" action="@render('formAction', 'd')" id="@render('formId', 'modalForm')">
I got "syntax error, unexpected '" action="' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ';'"
When I look at the actual php file (compiled), I see the following php.
<form method="<?php echo \Radic\BladeExtensions\Helpers\Partial::renderBlock('formMethod', 'POST')" action="@render('formAction', 'd'); ?>"
id="<?php echo \Radic\BladeExtensions\Helpers\Partial::renderBlock('formId', 'modalForm'); ?>">
As you see the @render for the 'action' didn't get converted.
Am I doing something wrong?
Hi,
would be great to be able to @push
something from the @embed
directive to the parent.
Example:
component.blade.php
@yield('content')
@push('js')
<script>alert('pushed 1!');</script>
@stack('js')
@endpush
layout.blade.php
@yield('content')
@stack('js')
page.blade.php
@extends('layout')
@section('content')
@embed('component')
Should push two scripts!
@push('js')
<script>alert('pushed 2!');</script>
@endpush
@endembed
@endsection
laradic/support wants 5.0.* and laravel 5.1 cant work with blade-extensions.
Any update is near?
It would be better to leave a single space between tags in minifying process as some templates use that single space instead of margin and it would be a hassle to fix those
PHP Fatal error: Cannot use 'String' as class name as it is reserved in G:
\Google_Drive\websites\singlejatt5\vendor\laradic\support\src\String.php on
line 136
Hi again.
I found another bug in BladeExtensions.
@foreach(App\Office::all() as $office)
@endforeach
runs 2 queries
select * from `offices`
select * from `offices`
If I disable Radic\BladeExtensions\BladeExtensionsServiceProvider
it runs just one unique query.
Can you explain this behaviour? Thanks
Thanks for great blade extension!
I want to call @embed with method.
Blade code
@embed('form', $model->getNameOptions())@endembed
But error has occurred.
compiled code
syntax error, unexpected ';'
<?php app('blade.embedding')->open('form', $model->getOptions()->insert(<<<'EOT'
)
EOT
)->close(); ?>
Can you fix this problem?
After I update to laravel 5.0.32. I found this error.
PHP Warning: Uncaught exception 'ErrorException' with message 'require(D:\dev\project\vendor\radic\blade-extensions\src\resources\config\blade_extensions.php): failed to open stre
am: No such file or directory' in D:\dev\project\vendor\laravel\framework\src\Illuminate\Support\ServiceProvider.php:64
So, I work around by copy resources folder into the src folder.
Please help to fix.
Hello, when i upgrade from 1.1.1 to 1.2.0:
Class 'Radic\BladeExtensions\Extensions\ForEachManager' not found
On blade template:
@if(!$loop->last),@endif
Downgrade fix the problem.
However great extension!
Regards.
arning: Ambiguous class resolution, "Radic\BladeExtensions\Facades\Markdown" was found in both "/var/www/vhosts/singlejatt.com/httpdocs/singlejatt5/vendor/radic/blade-extensions/src/Facades/Markdown.php" and "/var/www/vhosts/singlejatt.com/httpdocs/singlejatt5/vendor/radic/blade-extensions/src/Facades/BladeString.php"
Ensure Blade Extensions supports Laravel versions: 5.0
/ 5.1
/ 5.2
/ 5.3
Currently the idea is to let the config file define which directives to disable/override using the version_overrides
key.
return [
'mode' => 'auto',
'directives' => [
'set' => 'Radic\\BladeExtensions\\Directives\\SetDirective',
'unset' => 'Radic\\BladeExtensions\\Directives\\UnsetDirective',
'breakpoint' => 'Radic\\BladeExtensions\\Directives\\BreakpointDirective',
// etc..
],
// Laravel version changes to support all larael versions
'version_overrides' => [
'5.0' => [
'breakpoint' => 'Radic\\BladeExtensions\\Directives\\Breakpoint50Directive'
],
'5.1' => [
'breakpoint' => null // 'disabled' the directive
],
'5.2' => [],
'5.3' => []
],
'disabled_directives' => [
'debug',
],
'overrides' => [
'debug' => [
'pattern' => '',
'replacement' => '',
],
],
];
This should also fix #58
I have this code
@embed('inspinia.box')
@section('title','Edit User')
@section('content')
@include('admin.users._form')
@endsection()
@endembed
it is failing with this error message:
Call to undefined method Radic\BladeExtensions\Helpers\EmbedStack::make()
at line:4
2: <?php $__env->startSection('title','Edit User'); ?>
3: <?php $__env->startSection('content'); ?>
4: <?php echo $__env->make('admin.users._form', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
5: <?php $__env->stopSection(); ?>
Hello,
Laravel 5.2,
Blade-exentesions 6.2
When doing php artisan vendor:publish --provider=Radic\BladeExtensions\BladeExtensionsServiceProvider
it returns : Nothing to publish for tag [].
Thanks, :)
Hi there,
I'm trying to use an older version of the package (v3.0) as we currently only support Laravel 5.0. When I do a composer update I get the following
Looking at the composer.json for v3 you can see the dependancy as follows
However checking on Packagist here it only shows v1.0.0 which requires PHP >= 5.5.9? See below...
This means that v3.0 can never be installed as it can't resolve a dependancy which doesn't exist. Am I missing something or has support for v3.0 been dropped?
Thanks
Hi,
would be great if you can nest the @minify
directive inside another @minify
directive, as below:
some.blade.php
@minify('html')
<div>
<h4>Yayyyy!</h4>
</div>
@endminify
main.blade.php
<script>
@minify('js')
var html = "@include('_some')";
@endminify
</script>
Thanks!
Any project using PHPStorm/Idea can have a .idea/blade.xml
file that configures custom blade directives. I've been adding them manually for many, many times now.
This could easily be done with a console command like blade-extensions:phpstorm
that'll add the blade directives. Doesn't even require the IDE to restart, works directly.
Hi, after installing this package
I started to have issues with @GrahamCampbell's Markdown package
https://github.com/GrahamCampbell/Laravel-Markdown
Upon further investigation it is due to the markdown features blade-extensions provide, hence I removed Laravel-Markdown and included "erusev/parsedown": "~1.5".
I change my blade template from
Markdown::convertToHtml(e($comment->body))
to
@markdown
{{$comment->body}}
@endmarkdown
However what I got instead was
<?php echo $comment->body; ?>
in my view. Would like to ask if I used the @markdown tag wrongly.
composer package erusev/parsedown is required, even that documentation says it is optional...
@set does not allow some of expression.
Eg.
@set('somevar',$object->getValue())
@set('somevar',$object->getValue('params'))
@set('somevar',somefunctionCall('Params'))
@set('somevar',Session::get('Params'))
Once I've use the expression above, It has nothing compiled in compiled template file and of cause it has no variable setting.
still not work around, please help to fix.
I'm sorry for the issue but even with the latest comit, I always have this error. I copied pasted the file you edited in the latest commit into vendor/radic/blade-extensions/src/
It renders this when I call @domacro('test', 'hey') :
@macro('test', $test) return ''; @endmacro @domacro('test', 'hey')
my index.blade.php containing :
@macro('test', $test)
return '<img src="' . $test . '" />';
@endmacro
When I keep '\Radic\BladeExtensions\Directives\MacroDirectives::attach($this->app)' in AppServiceProvider.php, I have the error
When I remove '\Radic\BladeExtensions\Directives\MacroDirectives::attach($this->app)' in AppServiceProvider.php, I have the error
I also renamed the form alias to 'form' or 'Form' and it doesn't change anything
Directives should be extendable and Blade Extensions should provide an easy way of adding, extending, replacing or removing directives. Something along the lines of
config/blade-extensions.php
return [
'directives' => [
'set' => 'Radic\\BladeExtensions\\Directives\\SetDirective',
'unset' => 'Radic\\BladeExtensions\\Directives\\UnsetDirective',
'breakpoint' => 'Radic\\BladeExtensions\\Directives\\BreakpointDirective',
// etc ..
],
// other config ..
]
Classes
interface DirectivesRegistry {
public function set($name, $handler = null)
public function call($name)
}
abstract class Directive
{
protected $pattern;
protected $replace;
protected $name;
public function handle($value){}
// getters, setters eg getPattern, setPattern, etc
}
class BreakpointDirective extends Directive
{
// @NAME is replaced by config key name
protected $pattern = '/(?<!\\w)(\\s*)@NAME(\\s*)/';
protected $replace = <<<'EOT'
<!-- breakpoint --><?php
if(function_exists('xdebug_break')){
var_dump(xdebug_break());
}
?>
EOT;
}
Implementation
foreach($config->get('blade-extensions.directives',[]) as $name => $handler){
/** @var {DirectivesRegistry} $registry */
$registry->set($name, $handler)
}
$registry->call('breakpoint')->handle('string with @breakpoint')
Hi
macro @embed is great. - Thank you
What about creating new macro @embedglobal - embed with global context which can directly access global variables in template?
Similar as {% embed %}
in TWIG, where this is standard behaviour
Thanks you.
Good evening! There is a small problem, if you write @foreach with a space before the parenthesis is the regular expression does not work. It would be nice to fix it. Thank U! I am sorry for my english)
Hi,
when using command : "composer update", the package causes the following error :
> php artisan clear-compiled
[ReflectionException]
Class blade.compiler does not exist
Out of the box code generated from blade templates includes the variable $__env
, assigned to an instance of Illuminate\View\Factory
.
When using blade-extensions $__env
is assigned to an instance of Radic\BladeExtensions\Helpers\EmbedStack
. This class has most of the same methods as Illuminate\View\Factory
, but it does not have them all. I have a directive that uses $__env->hasSection($section)
. This method is not in the Radic\BladeExtensions\Helpers\EmbedStack
class.
To ensure the default behavior of $__env
is maintained when using blade-extensions the following could be added to Radic\BladeExtensions\Helpers\EmbedStack
.
/**
* Dynamically call the view factory instance.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public function __call($method, $parameters)
{
return call_user_func_array([$this->viewFactory, $method], $parameters);
}
Good day!
When the composer update
pops up an error:
Error Output: PHP Warning: Uncaught exception 'ErrorException' with message 'require(/mysite/vendor/radic/blade-extensions/src/resources/config/blade_extensions.php): failed t
o open stream: No such file or directory' in /mysite/vendor/laravel/fra
mework/src/Illuminate/Support/ServiceProvider.php:64
I decided to move a folder in the appropriate directory.
It is not exactly clear how to go about accessing the loop data described in the documentation, or what particular use cases exist.
I've tried to access it as shown in the documentation (see below). However, I get a Trying to get property of non-object
error.
@foreach($stuff as $key => $val)
$loop->index; // int, zero based
$loop->index1; // int, starts at 1
$loop->revindex; // int
$loop->revindex1; // int
$loop->first; // bool
$loop->last; // bool
$loop->even; // bool
$loop->odd; // bool
$loop->length; // int
@endforeach
Am I missing something?
Thanks
Hi !
@minify('html') does not work on v1.* ?
problem is in dependency on Sebwite/support
PHP error
Class 'Sebwite\Support\Vendor\Stringy' not found
in Sebwite .gitignore is vendor/*
Compiling markdown / adding markdown engine is outside of the package its scope. This can better be achieved by using interfaces which allow integration of custom parsers or parsers from other markdown packages.
A default markdown parser class should be added that (optinally / composer suggest) depends on a external parser library like Cebe Markdown to keep providing the @markdown
directive
Using @set
right after @foreach
throws FatalErrorException in daf5b1ff7385a6726aacd9e899b61add line 42: syntax error, unexpected '<'
For example:
@foreach( $categories as $c )
@set('products_cnt', count($c->products))
throws error, but putting @set
within any tag
@foreach( $categories as $cat )
<i>@set('products_cnt', count($c->products))</i>
works just fine
"Undefined variable: companyHomeUrl"
in the compiled view : @set('companyHomeUrl', 'toto')
The update has broken all my views which are now rendered as string
Trait BladeExtenderTrait throws exception
ReflectionException in Container.php line 741: Class blade.compiler does not exist
$blade = $app->make('blade.compiler'); //error
//should be
$blade = $app->make('view')->getEngineResolver()->resolve('blade')->getCompiler();
I'm running a homestead server. I'm on 6.0.1
and on Laravel v5.1.17
.
resources/views/home.blade.php
:
@section('content')
@embed('test')
@section('body')
<p>hello world</p>
@stop
@endembed
@stop
resources/views/test.blade.php
:
test
@yield('body')
I keep getting a File Not Found Exception.
FileNotFoundException in Filesystem.php line 381:
File not found at path: home/vagrant/Brandon/playground/resources/views/test.blade.php
in Filesystem.php line 381
at Filesystem->assertPresent('home/vagrant/Brandon/playground/resources/views/test.blade.php') in Filesystem.php line 176
at Filesystem->read('/home/vagrant/Brandon/playground/resources/views/test.blade.php') in FilesystemAdapter.php line 56
at FilesystemAdapter->get('/home/vagrant/Brandon/playground/resources/views/test.blade.php') in EmbedStack.php line 107
at EmbedStack->getViewFileContent() in EmbedStack.php line 117
at EmbedStack->getBladeCompiledViewFileContent() in EmbedStack.php line 73
at EmbedStack->end() in Stacker.php line 95
at Stacker->end() in 463c15d2b82dcde93063ea8acb851a8a line 34
Any ideas?
So I have been delving into your code this evening to find out that JIT PCRE compiler ran into a stacklimit error. This caused the problem that no embed tags were replaced anymore and were showing up as cleartext on the page. Aside from probably documenting this to prevent other people from running into it you could perhaps test the preg_last_error() before wildly assuming it worked.
Great package by the way.
For those seeking a solution:
ini_set('pcre.jit', false);
Hello,
Here's my composer
"php": ">=5.5.9",
"laravel/framework": "5.1.",
"illuminate/html": "5.",
"kozz/laravel-guzzle-provider": "6.0",
"caouecs/laravel4-lang": "~2.0",
"nesbot/carbon": "~1.14",
"radic/blade-extensions": "~4.0",
"laravelcollective/html": "5.1.*",
"raveren/kint": ">=0.9.1",
"erusev/parsedown": "~1.5"
I added in config/app.php for providers :
Collective\Html\HtmlServiceProvider::class,
Radic\BladeExtensions\BladeExtensionsServiceProvider::class
I added aliases:
'Form' => Collective\Html\FormFacade::class,
'HTML' => Collective\Html\HtmlFacade::class,
My template contains :
@macro('simple', $first, $second = 3, $what)
$who = $first . $second;
return $what . $who;
@endmacro
which is rendered as text with @domacro('simple')
Laravel 5.1
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.