PHPackages                             rapid/bladex - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. rapid/bladex

ActiveLibrary[Templating &amp; Views](/categories/templating)

rapid/bladex
============

Advanced laravel blade.

2.1(2y ago)28MITPHP

Since Oct 29Pushed 2y ago1 watchersCompare

[ Source](https://github.com/MahdiSaremi/BladeX)[ Packagist](https://packagist.org/packages/rapid/bladex)[ RSS](/packages/rapid-bladex/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (4)Dependencies (2)Versions (6)Used By (0)

BladeX v2
=========

[](#bladex-v2)

This package adds some features to make it easier to work with components and html tags in laravel blade.

```

    BladeX

    Click here

```

- [BladeX v2](#bladex-v2)
    - [Requirements](#requirements)
    - [Installation](#installation)
    - [Compiling](#compiling)
    - [Components](#components)
        - [Name Rule](#name-rule)
        - [Component Path](#component-path)
    - [Call Component](#call-component)
    - [Slots](#slots)
    - [Use Component](#use-component)
    - [Use View Like Components](#use-view-like-components)
    - [Use All (\*)](#use-all-)
    - [Layouts](#layouts)
    - [Directive Helpers](#directive-helpers)
        - [Layout](#layout)
        - [Partial](#partial)
    - [Current Directory Name](#current-directory-name)
    - [Configuration](#configuration)
    - [Support](#support)

Requirements
------------

[](#requirements)

- Php 8.1 or higher
- Laravel 10.0 or 11.0

Installation
------------

[](#installation)

Install the package with composer:

```
composer require rapid/bladex
```

Then clear the compiled view caches to recompile blade files:

```
php artisan view:clear
```

Compiling
---------

[](#compiling)

BladeX converts the components tag into proper php code at compile time! Some operations are not at runtime.

This means that if you change something that doesn't recompile the source file, but affects the code, you have to clear the compiled caches to recompile:

```
php artisan view:clear
```

Components
----------

[](#components)

You can call components by `` in anywhere you want!

### Name Rule

[](#name-rule)

The component call name should be `PascalCase`, but the file name should be `kebab-case`.

### Component Path

[](#component-path)

Every folder named `components` is a component path.

Exmaples:

View PathTag NameView-Based Name`components/button.blade.php``Button``button``components/button/red.blade.php``Button.Red``button.red``components/button/index.blade.php``Button``button``componets/posts/post-card.blade.php``Posts.PostCard``posts.post-card``posts/components/post-card.blade.php``Posts.PostCard``posts.post-card``posts/actions/components/del.blade.php``Posts.Actions.Del``posts.actions.del`Call Component
--------------

[](#call-component)

Just type ``:

```
Delete
Cancel

```

> Note: If the component file is not found at compile time, the component will not compile.

Slots
-----

[](#slots)

In the blade, you must write `` to define slot value.

But in BladeX, just type ``:

```

    Select Option

        Option 1
        Option 2

        ...

```

Use Component
-------------

[](#use-component)

If you want to call component by alias (like programming use keyword), you can use magic blade directive `@use`:

```
@use(Posts.Actions.Del)

```

Add `as` keyword to set alias:

```
@use(Posts.Actions.Del as PostDelete)

```

You can also use a component folder:

```
@use(Posts.Actions as PostAct)

```

Use View Like Components
------------------------

[](#use-view-like-components)

If you want to use it by specifying the view path, you can use this syntax:

```
@use('home.post' as Post)

```

```

@use('layout.app-layout')

```

Use All (\*)
------------

[](#use-all-)

If you want to use all components in same directory/name, you can write `@use` directive with `.*` suffix:

```
@use(Posts.Actions.*)

```

```
@use('layouts.*')

    Hello World

```

> **Note**: Try not to spam this feature.
>
> Because this feature searches among the files and slows down the compiling view
>
> However, all lookups are done at compile time only. So don't worry about the slowness of the website :)

Layouts
-------

[](#layouts)

You can create layouts with BladeX. For example:

- layouts/app.blade.php

```

    {{ $title }}

    {{ $slot }}

```

- index.blade.php

```
@use('layouts.app' as AppLayout)

    BladeX

    Welcome to BladeX!

```

> You don't need `@use` tag anymore if you create `.blade.php` configuration file! [More Info](#configuration)

Directive Helpers
-----------------

[](#directive-helpers)

### Layout

[](#layout)

Layout equals to `@extends`, but only adds `layouts.` name to your view name. For example `@layout('guest')` converts to `@extends('layouts.guest')` and `@layout('admin.main')` to `@extends('admin.layouts.main')`

```
@layout('guest')

@section('content')
    Hello World
@endsection
```

> Also, you can use components for layouts.

### Partial

[](#partial)

Partial equals to `@include`, but only adds `partials.` name to your view name. For example `@partial('edit')` converts to `@include('partials.edit')` and `@partial('admin.delete')` to `@include('admin.partials.delete')`

```

    @partial('users.my-info')

```

Current Directory Name
----------------------

[](#current-directory-name)

You can use `@` in `@include`, `@use`, `@layout`, `@extends`, `@partial` to use current path reference.

- admin/dashboard.blade.php:

```
@use('admin.btn-create')
@use('@btn-create')

@include('admin.partials.create-user')
@include('@partials.create-user')
@partial('@create-user')
```

Configuration
-------------

[](#configuration)

Add the `.blade.php` file wherever you want to apply the sub files:

```
