PHPackages                             froiden/knife - 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. froiden/knife

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

froiden/knife
=============

Laravel package providing additional blade directives.

v5.1.2(10y ago)3521MITPHPPHP &gt;=5.5.9

Since Jun 26Pushed 10y ago3 watchersCompare

[ Source](https://github.com/Froiden/knife)[ Packagist](https://packagist.org/packages/froiden/knife)[ Docs](https://github.com/Froiden/knife)[ RSS](/packages/froiden-knife/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (5)Dependencies (1)Versions (7)Used By (0)

Knife
=====

[](#knife)

Knife is an extension for Laravel's Blade template engine to support some handy directives that are not included in default blade syntax.

Supported Directives
--------------------

[](#supported-directives)

- **@datetime**, **@date**, **@time** - Display date-time, date and time as string respectively. Directives accepts all valid dates/objects that can be parsed by [Carbon's](http://carbon.nesbot.com) parse method. You can use **config file** for knife to define date-time format to be used.
- **@use** - Import a class from a different namespace and use it in code without always specifying full class path.
- **@nl2br** - Display text with new lines replaced by `` tag.
- **@escape** - Display text by escaping quotes and other characters. It basically used `addslashes()` method. Its very useful when outputting text in JavaScript string.
- **@breakpoint** - Add an **xdebug** breakpoint at the specified place. Helps in debugging generated views.
- **@set** - Define a new variable.

This is first version of library. More directives will be added soon.

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

[](#installation)

**Note:** Knife is only supported on **Laravel 5.1** or later.

1. First add library using composer:

    `composer require froiden/knife:~5.1`
2. Add service provider to `app.php`:

    ```
    Froiden\Knife\KnifeServiceProvider::class
    ```

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

[](#configuration)

You can specify date-time formats to be used by in Knife's config file. To use this, export the config file as follows:

`php artisan vendor:publish`

The config file with name **knife.php** will be created in the config folder where all other configs are.

Some examples
-------------

[](#some-examples)

```
@use('Carbon\Carbon') // Observe that we have used only Carbon below instead of \Carbon\Carbon

@datetime('now') // 28th August 2015, 11:27 am
@date('now') // 28th August 2015
@time('2015-08-28 09:37:38') // 09:37 am

@set($count, 1)
{{ $count++ }} // 1
{{ $count++ }} // 2

@set($new)
{{ $new }}
{{ Carbon::now() }} // 2015-08-28 09:37:38

$bio =
