Code Monkey home page Code Monkey logo

laravel-blade-directives's Introduction

Laravel Blade Directives

Latest Version on Packagist Total Downloads Software License Build Status

A collection of nice Laravel Blade directives.

Installation

You can install the package via composer:

composer require appstract/laravel-blade-directives

Usage

@istrue

Only show when $variable isset and true.

@istrue($variable)
   This will be echoed
@endistrue

Or when you would like to quickly echo

@istrue($variable, 'This will be echoed')

@isfalse

Same as @istrue but checks for isset and false.

@isfalse($variable)
   This will be echoed
@endisfalse

@isnull

Only show when $variable is null.

@isnull($variable)
   This will be echoed
@endisnull

@isnotnull

Same as @isnull but one shows when $variable is not null.

@isnotnull($variable)
   This will be echoed
@endisnotnull

@dump and @dd

@dump($var)

@dd($var)

@mix

Create a HTML element to your Laravel-Mix css or js.

@mix('/css/app.css')
@mix('/js/app.js')

Output:

<link rel="stylesheet" href="{{ mix('/css/app.css') }}">
<script src="{{ mix('/js/app.js') }}"></script>

@style

Create a <style> element or <link> element with a css path.

@style
    body { background: black }
@endstyle


@style('/css/app.css')

@script

Create a <script> element with or without a js path.

@script
    alert('hello world')
@endscript


@script('/js/app.js')

@inline

Load the contents of a css or js file inline in your view.

@inline('/js/manifest.js')

@pushonce

Same as @push but will include content one time only. Useful for repeatable blocks.

First parameter must follow the syntax stack-name:group-name.

@pushonce('js:foobar')
    <script src="{{ asset('/js/foobar.js') }}"></script>
@endpushonce

Include pushes with standard @stack directive:

@stack('js')

@routeis

Checks if the current route name is equal to the given parameter. You can use a wildcard like blog.post.*.

@routeis('webshop.checkout')
    Do something only on the checkout
@endrouteis

@routeisnot

Checks if the current route name is not equal to the given parameter. You can use a wildcard like blog.post.*

@routeisnot('webshop.checkout')
    Do something only if this is not the checkout
@endrouteisnot

@instanceof

Checks if the first parameter is an instance of the second parameter.

@instanceof($user, 'App\User')
    User is an instance of App\User
@endinstanceof

@typeof

Checks if the parameter is of a certain type.

@typeof($text, 'string')
    Text is a string
@endtypeof

@repeat

Repeat something a specified amount of times.

@repeat(3)
    Iteration #{{ $iteration }}
@endrepeat

@fa, @fas, @far, @fal, @fab, @fad, @mdi, @glyph

Quickly output an icon with Font Awesome, Material Design Icons or Glyphicon.

@fa('address-book', 'optional-extra-class')

// for Font Awesome 5 (solid, regular, light, brand, duotone):
@fas('address-book', 'optional-extra-class')
@far('address-book', 'optional-extra-class')
@fal('address-book', 'optional-extra-class')
@fab('address-book', 'optional-extra-class')
@fad('address-book', 'optional-extra-class')

// for Material Design Icons
@mdi('account', 'optional-extra-class')

// for Glyphicons
@glyph('glass', 'optional-extra-class')

@data

Output data-attributes from an array.

@data(['testing' => 123])

@haserror

Quickly output for classical $errors->has('input_name') to determine if any error messages exist for a given field.

@haserror('input_name')
    This input has an error
@endhaserror

@count

Output number of entries.

@count([1,2,3])

@nl2br

Replaces \n into <br>.

@nl2br('foo\n bar\n baz\n')

@snake, @kebab, @camel

Output formatted string (uses Laravel Helpers).

@snake('fooBar')
// output: 'foo_bar'

@kebab('fooBar')
// output: 'foo-bar'

@camel('foo bar')
// output: 'fooBar'

Testing

composer test

Contributing

Contributions are welcome, thanks to y'all :)

About Appstract

Appstract is a small team from The Netherlands. We create (open source) tools for Web Developers and write about related subjects on Medium. You can follow us on Twitter, buy us a beer or support us on Patreon.

License

The MIT License (MIT). Please see License File for more information.

laravel-blade-directives's People

Contributors

adriaroca avatar akoepcke avatar aziev avatar bgencacat avatar breart avatar f-liva avatar fgilio avatar gboquizosanchez avatar gizburdt avatar jornatf avatar kishdia avatar lloricode avatar m1guelpf avatar ovanschie avatar rennokki avatar roni-estein avatar serderovsh avatar stylecibot avatar svenluijten avatar teuunn 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  avatar  avatar

laravel-blade-directives's Issues

Error if pushonce group-name contains dash "-"

Blade

@pushonce('end:popup-jenis')
<script>
    alert('once');
</script>
@endpushonce

Parse error: syntax error, unexpected '='

Code generated:

<?php if(! isset($__env->__pushonce_end_popup-jenis)): $__env->__pushonce_end_popup-jenis = 1; $__env->startPush('end'); ?>

More directives

I have a few directives I created for my projects, and I thought you could be interested in adding some to this package:

  • Repeat and EndRepeat: A for loop that repeats the contents the number of times specified. Example:
@repeat(3)
Test
@endrepeat
  • Production: A custom IF directive that only runs when in production
  • Local: Same as above but for local enviroment

@pushonce directive

Hello,

I wrote a @pushonce directive to push a code block only once time (useful for blade partials included multiple times in a master). Are you interested in a PR?

@fa directive

Could we include a param in this to add more classes, "fa-lg" for example.

@fa('address-book', 'fa-lg')

@script is broken

Commit 16f9053 broke the @script directive.

@antoniancu, blade directives simply don't work like that.

    'script' => function ($expression) {
        if (! empty($expression)) {
            $expression = DirectivesRepository::parseMultipleArgs($expression);
            $defer = $expression->get(1) ? ' defer' : '';

            return '<script src="'.DirectivesRepository::stripQuotes($expression->get(0)).'"'.$defer.'></script>';
        }

        return '<script>';
    },

I'm surprised how nobody noticed that in nearly two months ...

Call to undefined method Closure::__set_state()

When executed the php artisan config cache command reports error in /bootstrap/cache/config.php on line 142.

`
'blade-directives' =>

array (

'directives' => 

array (

  'name' => 

  Closure::__set_state(array( // Line 142

  )),

),

),`

In order for it to continue to work, you must delete the cached configuration file.

Laravel 10

Is there going to be an small update for laravel 10 ?

Directive @fa with FontAwsome 5.x

Hi,

Thank you for this good repository.
Just for your information, since Font Awesome 5.x, the syntax have changed.
For example:

// FontAwesome 5.x
<i class="fas fa-user"></i>

// @fa('user') don't working
<i class="fa fa-user"></i>

// @fa('user', 'fas') working with FontAwesome 5.x
// But it's not correct syntax
<i class="fa fa-user fas"></i>

Because since 5.x, we have three icon styles.

  • fas : for solid icons
  • far : for regular icons
  • fab : for brands's icon

@pushonce directive issue

@pushonce directive was ok in my local environment. but blade is not compiling it (showing @pushonce and @endpushonce as text in browser ) for my dev environment in aws.

any ideas ?

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.