Skip to content

Laravel Blade Template extensions like $loop->odd/$loop->index/etc in foreach

License

Notifications You must be signed in to change notification settings

thoresuenert/blade-extensions

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Blade Extensions

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

Laravel package providing additional Blade extensions.

Implemented and tested directives:

  • @foreach (with $loop data, like twig)
  • @break
  • @continue
  • @set
  • @debug

Version 1.0.0beta

View changelog and todo

Overview

@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

    @break

    @continue
@endforeach

@set('newvar', 'value')
{{ $newvar }}


@debug($somearr)

Requirements

  • PHP > 5.3
  • Laravel > 4.0
  • (optional) raveren/kint > 0.9.1

Installation

Add to composer.json

"radic/blade-extensions": "1.*"

Add to app/config/app.php to register the service provider

'Radic\BladeExtensions\BladeExtensionsServiceProvider'

Configuration

Publish the configuration file php artisan config:publish radic/blade-extensions

return array(
    /*
     * Blacklisting of directives. These directives will not be extended. Example:
     *
     * 'blacklist' => array('foreach', 'set', 'debug')
     */
    'blacklist' => array(),

    /*
     * Prepend and append the debug output.
     */
    'debug' => array(
        /*
         * Prepend any code in front of our variable name
         *
         * The default config also checks if Kint is installed for sweet debug output.
         * Check https://github.com/raveren/kint.
         *
         */
        'prepend' => "<h1>DEBUG OUTPUT:</h1><pre><code><?php " . (class_exists('Kint') ? "Kint::dump(" : "var_dump("),

        /*
         * Append any code behind our variable name
         */
        'append' => ") ?></code></pre>"
    )
);

@debug with raveren/kint

Screenshot

Copyright/License

Copyright 2014 Robin Radic - MIT Licensed

About

Laravel Blade Template extensions like $loop->odd/$loop->index/etc in foreach

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%