PHPackages                             leitsch/kirby-blade - 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. leitsch/kirby-blade

ActiveKirby-plugin[Templating &amp; Views](/categories/templating)

leitsch/kirby-blade
===================

Enable Laravel Blade Template Engine for Kirby 4 and Kirby 5

3.1.1(11mo ago)219.2k↓43.2%3[2 PRs](https://github.com/lukasleitsch/kirby-blade/pulls)MITPHPPHP ^8.2CI passing

Since Jun 22Pushed 5mo ago2 watchersCompare

[ Source](https://github.com/lukasleitsch/kirby-blade)[ Packagist](https://packagist.org/packages/leitsch/kirby-blade)[ RSS](/packages/leitsch-kirby-blade/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (38)Used By (0)

Kirby Blade
===========

[](#kirby-blade)

[![Source](https://camo.githubusercontent.com/ef0b61270c2881030956dbdd67f525d9dc14b217ecf0fadc3d4bb0f5e6362dfe/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d6c756b61736c6569747363682f6b697262792d2d626c6164652d626c75653f7374796c653d666c61742d737175617265)](https://github.com/lukasleitsch/kirby-blade)[![Download](https://camo.githubusercontent.com/c32a1d8be1f1bab7c8c3dd6f52dd54ce1f1fd64bc369ca6ad553112ac143b348/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6569747363682f6b697262792d626c6164653f7374796c653d666c61742d737175617265)](https://github.com/lukasleitsch/kirby-blade)[![Open Issues](https://camo.githubusercontent.com/e1569f741ad56ca73dfdc517d1ce623485bec399ef3520db44891ac406f29beb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d7261772f6c756b61736c6569747363682f6b697262792d626c6164653f7374796c653d666c61742d737175617265)](https://github.com/lukasleitsch/kirby-blade)[![Last Commit](https://camo.githubusercontent.com/184dbf04cb2208654a1055af8aaf1b7135a17cdb6e90b262cfa84bbf3223c2e9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f6c756b61736c6569747363682f6b697262792d626c6164653f7374796c653d666c61742d737175617265)](https://github.com/lukasleitsch/kirby-blade)[![Release](https://camo.githubusercontent.com/95b7ea6e008d25cea9911e622f6b69cb1a12fc45d2859aff05c402c0610c6429/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6c756b61736c6569747363682f6b697262792d626c6164653f7374796c653d666c61742d737175617265)](https://github.com/lukasleitsch/kirby-blade)[![License](https://camo.githubusercontent.com/a2c85d1f87de0b6f40c49bb44d8f47b321a25860659c87dde9046b3104f6b44a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6c756b61736c6569747363682f6b697262792d626c6164653f7374796c653d666c61742d737175617265)](https://github.com/lukasleitsch/kirby-blade)

Kirby Blade use Laravel `illuminate/view` 12.x package and compatible with Kirby 4 and Kirby 5.

This package enables [Laravel Blade](https://laravel.com/docs/12.x/blade) for your own Kirby applications.

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

[](#installation)

```
composer require leitsch/kirby-blade

```

**Caveat:** Laravel and Kirby both define the `e()` helper function, but they do vastly different things. In Kirby, `e()` is basically just a shortcut for `echo $condition ? $a : $b;`. In Laravel, this function escapes HTML characters in a string. From Kirby 3.7 and up, you have to disable Kirby’s own `e()` helper by adding a single line of code to your `index.php`, before including the `autoload.php` file:

```
define('KIRBY_HELPER_E', false);
```

What is Blade?
--------------

[](#what-is-blade)

According to Laravel Blade documentation is:

> Blade is the simple, yet powerful templating engine that is included with Laravel. Unlike some PHP templating engines, Blade does not restrict you from using plain PHP code in your templates. In fact, all Blade templates are compiled into plain PHP code and cached until they are modified, meaning Blade adds essentially zero overhead to your application. Blade template files use the .blade.php file extension.

Usage
-----

[](#usage)

You can use the power of Blade like [Layouts](https://laravel.com/docs/12.x/blade#building-layouts), [Forms](https://laravel.com/docs/12.x/blade#forms), [Sub-Views](https://laravel.com/docs/12.x/blade#including-subviews), [Components](https://laravel.com/docs/12.x/blade#components), [Directives](https://laravel.com/docs/12.x/blade#blade-directives) and your custom if statements.

All the documentation about Laravel Blade is in the [official documentation](https://laravel.com/docs/12.x/blade).

Options
-------

[](#options)

The default values of the package are:

OptionDefaultValuesDescriptionleitsch.blade.templatessite/templates(string)Location of the templatesleitsch.blade.viewssite/cache/views(string)Location of the views cachedleitsch.blade.directives\[\](array)Array with the custom directivesleitsch.blade.ifs\[\](array)Array with the custom if statementsAll the values can be updated in the `config.php` file.

### Templates

[](#templates)

Default templates folder is `site/templates` directory or wherever you define your `templates` directory, but you can change this easily:

```
'leitsch.blade.templates' => '/theme/default/templates',
```

### Views

[](#views)

All the views generated are stored in `site/cache/views` directory or wherever you define your `cache` directory, but you can change this easily:

```
'leitsch.blade.views' => '/site/storage/views',
```

### Directives

[](#directives)

By default, Kirby Blade comes with following directives:

```
@asset($path)
@csrf()
@css($path)
@dump($variable)
@e($condition, $value, $alternative)
@get($key, $default)
@gist($url)
@go($url, $code)
@h($string, $keepTags)
@html($string, $keepTags)
@js($path)
@image($path, $attr) // @image('forrest.jpg', 'url')
@kirbytag($type, $value, $attr)
@kirbytags($text, $data)
@kirbytext($text, $data)
@kirbytextinline($text)
@kt($text)
@markdown($text)
@option($key, $default)
@page($key, $attr) // @page('blog', 'title')
@param($key, $fallback)
@site($attr) // @site(title')
@size($value)
@smartypants($text)
@snippet($name, $data)
@svg($file)
@t($key, $fallback)
@tc($key, $count)
@tt($key, $fallback, $replace, $locale)
@u($path, $options)
@url($path, $options)
@video($url, $options, $attr)
@vimeo($url, $options, $attr)
@widont($string)
@youtube($url, $options, $attr)
```

But you can create your own:

```
'leitsch.blade.directives' => [
    'greeting' => function ($text)
    {
        return "";
    },
],
```

Kirby Helpers Documentation:

### If Statements

[](#if-statements)

Like directives, you can create your own if statements:

```
'leitsch.blade.ifs' => [
    'logged' => function ()
    {
        return !!kirby()->user();
    },
],
```

After declaration, you can use it like:

```
@logged
    Welcome back {{ $kirby->user()->name() }}
@else
    Please Log In
@endlogged
```

### Anonymous components

[](#anonymous-components)

To define an anonymous component, you only need to place a Blade template within your `site/templates/components` directory. To render an alert component you have to define `site/templates/components/alert.blade.php` and the component can be rendered like:

```

```

More about anonymous components in the [official Laravel Blade documentation](https://laravel.com/docs/12.x/blade#anonymous-components).

### Class based components

[](#class-based-components)

For class based components, the app namespace must be added to your project `composer.json`.

```
{
    "autoload": {
        "psr-4": {
            "App\\": "app/"
        }
    }
}
```

The class must be placed in the `site/components` directory and will be autoloaded by the package.

A button class could look like:

```
