PHPackages                             dijitaltrix/scythe-view - 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. dijitaltrix/scythe-view

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

dijitaltrix/scythe-view
=======================

Render blade templates into a PSR-7 Response object.

v0.9.3(8y ago)036MITPHP

Since Mar 12Pushed 8y ago1 watchersCompare

[ Source](https://github.com/dijitaltrix/Scythe-View)[ Packagist](https://packagist.org/packages/dijitaltrix/scythe-view)[ RSS](/packages/dijitaltrix-scythe-view/feed)WikiDiscussions master Synced yesterday

READMEChangelog (3)Dependencies (2)Versions (5)Used By (0)

Scythe View
===========

[](#scythe-view)

*pronounced \[sahyth\] - Olde English word for a curved blade for cutting by hand*

[![Build Status](https://camo.githubusercontent.com/da1533e4575aae14ca6f06fbf21cd2ee661b95403c222c3c49bdb618685f4860/68747470733a2f2f7472617669732d63692e6f72672f64696a6974616c747269782f5363797468652d566965772e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/dijitaltrix/Scythe-View)

A simple implementation of Laravel Blade for rendering blade syntax in views into a PSR-7 Response object. This has no dependencies and it works great with Slim Framework 3.

If you're unfamiliar with Blade as a view renderer it's main advantage is it's *lightness*, it is essentially a simple wrapper around PHP. The syntax behaves as a PHP programmer would expect it to, so for those familar with PHP there is very little mental juggling required to understand Blade.

This implementation does not aim for feature parity, that is beyond the scope of this project. It does offer some useful methods and the ability to add custom directives through callbacks. If you need full compatibility you can use the full Laravel Blade package via [philo/laravel-blade](https://packagist.org/packages/philo/laravel-blade).

**Note:** Currently unsupported features `@verbatim` `@component` `@hasSection` `@auth`\* `@guest`\*

\*These could be added using a directive callback to suit your framework

### Table of Contents

[](#table-of-contents)

- [Installation](#installation)
- [Getting Started](#getting_started)
- [Language Reference](#language_reference)
    - [Comments](#comments)
    - [Variables](#variables)
    - [Variable manipulation](#variable_manipulation)
    - [Control Structures](#control_structures)
    - [Loops](#loops)
    - [Inheritance](#inheritance)
    - [Directives](#directives)
    - [Stacks](#stacks)
- [Methods](#methods)
    - [addDirective](#addDirective($placeholder,_$callback))
    - [addNamespace](#addNamespace($name,_$path))
    - [exists](#exists($template))
    - [renderString](#renderString($string,_$data=%5B%5D))
- [To do or not to do](#to_do_or_not_to_do)

Installation
============

[](#installation)

Install with [Composer](http://getcomposer.org):

```
composer require dijitaltrix/scythe-view
```

Getting started
---------------

[](#getting-started)

### Use with Slim 3

[](#use-with-slim-3)

Add Scythe to your container, passing the required parameters `views_path` and `cache_path`

```
$container['view'] = function($c) {
    return new \Dijitaltrix\Views\Scythe([
        'views_path' => 'path/to/views',
        'cache_path' => 'path/to/cache',
    ]);
}
```

And assuming you set views\_path as `app/src/views` you may use it as follows:

```
// app/routes.php
$app->get('/hello/{name}', function ($request, $response, $args) {
    return $this->view->render($response, "hello", $args);
});

// app/src/views/hello.blade.php
Hello {{ $name }}
```

You may add namespaces and directives using the methods outlined in the Methods section below.

### Use with any PSR-7 Project

[](#use-with-any-psr-7-project)

```
$view = new \Dijitaltrix\Views\Scythe([
    'views_path' => 'path/to/views',
    'cache_path' => 'path/to/cache',
]);

$response = $view->render(new Response(), "/path/to/template", $data);
```

Language Reference
==================

[](#language-reference)

Comments
--------

[](#comments)

```
{{-- Upon rendering all this will be removed --}}
```

Opening and closing php tags can be used follows `@php` `@endphp`

Variables
---------

[](#variables)

All variable display functions will escape your output using htmlentities() except for echo raw: `{!! $danger !!}`

### echo

[](#echo)

Displays the contents of $name

```
{{ $name }}
//
```

### echo raw

[](#echo-raw)

Use this with caution when displaying user generated data

```
{!! $name !!}
//
```

### echo with a default

[](#echo-with-a-default)

Displays 'Anonymous' if $name is not set

```
{{ $name or 'Anonymous' }}
//
```

### set

[](#set)

Sets the value of a variable

```
@set($muppet, 'Kermit')
//
```

### unset

[](#unset)

Removes a variable from the scope

```
@unset($muppet)
//
```

### isset

[](#isset)

Checks whether a variable is set

```
@isset($muppet)
He is here
@endisset
```

### has

[](#has)

Checks whether a variable is set and has a value

```
@has($muppet->name)
Muppet name is set and is not empty
@endhas
```

Variable manipulation
---------------------

[](#variable-manipulation)

Twig has some really nice string modifiers, we have these ;) All examples below are wrapped with htmlentities()

### upper

[](#upper)

Converts the string to uppercase

```
@upper($name)

```

### lower

[](#lower)

Converts the string to lowercase

```
@lower($name)

```

### ucfirst

[](#ucfirst)

Converts the string to lowercase, then capitalises the first word

```
@ucfirst($name)

```

### ucwords

[](#ucwords)

Converts the string to lowercase, then capitalises each word

```
@ucwords($name)

```

### format

[](#format)

This is just a wrapper around the sprintf function, to help your muscle memory you may also call it as @sprintf

```
@format("There were %s in the %s", "dogs", "yard")

```

### wrap

[](#wrap)

```
@wrap("This is a really long line that should wrap somewhere otherwise it may shatter the internet into pieces!")

@wrap("This is a really long line that should wrap somewhere otherwise it may shatter the internet into pieces!", 25)

```

Control structures
------------------

[](#control-structures)

### if

[](#if)

Scythe supports all possible combinations of if structures

```
@if (true)
This will always show
@endif
```

```
@if (true)
This will always show
@else
This will never show
@endif
```

```
@if ($i == 1)
i is equal to one
@elseif ($i == 2)
i is equal to two
@else
i is something else entirely
@endif
```

### unless

[](#unless)

If NOT something, then what?

```
@unless($bank > 1000000)
Keep on working
@endunless
```

### switch

[](#switch)

```
@switch($i)
    @case(1)
        i is equal to one
        @break
    @case(2)
        i is equal to two
        @break
    @default
        i is something else entirely
@endswitch
```

Loops
-----

[](#loops)

### for

[](#for)

```
@for ($i = 0; $i < 11; $i++)
    Currently reading {{ $i }}
@endfor
```

### foreach

[](#foreach)

```
@foreach ($muppets as $muppet)
    Say howdy to {{ $muppet->name }}
@endforeach
```

### forelse

[](#forelse)

```
@forelse ($muppets as $muppet)
    Say howdy to {{ $muppet->name }}
@empty
    Sadly no muppets can be with us today
@endforelse
```

### while

[](#while)

```
@while (true)
    One Infinite Loop
@endwhile
```

### each

[](#each)

A more compact version of the foreach loop that adds the @include command

```
@each('muppets/profile', $muppets, 'muppet')

// @foreach ($muppets as $muppet)
//   @include('muppets/profile')
// @endforeach
```

It also supports the generation of the forelse structure if you pass a view to display when there are no records

```
@each('muppets/profile', $muppets, 'muppet', 'muppets/profile-missing')

// @forelse ($muppets as $muppet)
//   @include('muppets/profile')
// @empty
//   @include('muppets/profile-missing')
// @endforelse
```

#### Loop variable

[](#loop-variable)

A loop helper is available, this works identically to the Blade $loop helper

**Property****Description**$loop-&gt;indexThe index of the current loop iteration (starts at 0).$loop-&gt;iterationThe current loop iteration (starts at 1).$loop-&gt;remainingThe iteration remaining in the loop.$loop-&gt;countThe total number of items in the array being iterated.$loop-&gt;firstWhether this is the first iteration through the loop.$loop-&gt;lastWhether this is the last iteration through the loop.$loop-&gt;depthThe nesting level of the current loop.$loop-&gt;parent\*When in a nested loop, the parent's loop variable.\*Not implemented yet

Inheritance
-----------

[](#inheritance)

### extends

[](#extends)

Calls a parent template to insert sections into

```
@extends('muppets/cast/list')
```

### section

[](#section)

Sections define areas of content to be inserted into a parent template

```
@section('title', 'Muppets cast listing')

@section('head')
Muppets cast listing
@endsection
```

#### parent

[](#parent)

Sections can be merged between templates using the @parent directive.

```

@section('sidebar')
    This is the sidebar content
@show

@section('sidebar')
    @parent

        This is a list item
        And so is this
        Another item in the list

@endsection
```

Will display as

```
This is the sidebar content

    This is a list item
    And so is this
    Another item in the list

```

### replace or yield

[](#replace-or-yield)

Replaced with the contents of the child template section definition

```
@replace('title')

@yield('title')

```

### include

[](#include)

Include another blade template, all variables will be available to the included template

```
@section('body')

@foreach ($muppets as $muppet)
    @include('muppets/cast/member')
@endforeach

@endsection
```

Directives
----------

[](#directives)

Define your own placeholders that insert content via callbacks

```
// output a string
$view->addDirective('/@hello/i', 'Hello world');

// output the result of a callback
$view->addDirective('/@hello/i', function(){
    return 'Hello world';
});
//TODO pass parameters from directive to callback
```

Stacks
------

[](#stacks)

Push to stacks from your child templates, then they will be appended to the @stack directive in your parent template

```
// child.blade.php
@extends('parent')

@section('title', 'The title')

@push('head')

@endpush

@push('scripts')

    alert('Some alert');

@endpush

// parent.blade.php

    @stack('head')

    @yield('body')
    @stack('scripts')

```

Methods
=======

[](#methods)

In addition to the Blade syntax, the renderer instance offers the following methods

### addDirective($placeholder, $callback)

[](#adddirectiveplaceholder-callback)

```
$view->addDirective('@rand', function() {
    if (rand(1,10) > 5) {
        throw new Exception("This is pointless");
    }
});
```

### addNamespace($name, $path)

[](#addnamespacename-path)

Namespaces allow you to add view paths outside the default views\_path. Use them for external packages or to help organise your code into modules.

```
// add the namespace name first, followed by the path to the root of the namespace
$view->addNamespace("admin", "/src/Admin/views");

// namespaces are referenced with '::'
// for example
$view->exists('admin::user/dashboard');

// this will load the file at src/Admin/views/user/profile.blade.php
$view->render($response, 'admin::user/profile', $args);
```

### exists($template)

[](#existstemplate)

The `exists()` function will return `true` if the template file is in the view path, or `false` if not.

```
$view->exists('admin/dashboard')

// Namespaces are specified as follows
$view->exists('admin::user/dashboard')
```

### renderString($string, $data=\[\])

[](#renderstringstring-data)

The `renderString()` function will parse a string converting any blade commands .

```
$blade = "{{ $title }}";

$view->renderString($blade, ['title'=>'The Muppet Show']);

// The Muppet Show
```

To do or not to do
==================

[](#to-do-or-not-to-do)

### Components and slots

[](#components-and-slots)

No plans to introduce this, use @include as an alternative.

### @inject

[](#inject)

No plans to implement this I feel it's not good practice to allow the view to pull in whatever data classes etc.. it likes. Data and dependencies should be generated in the 'Domain' and injected into the view Response so the view should already have everything it needs.

As the template renders down to plain php you are of course able to execute in any code you like between PHP tags.

### Custom if statements

[](#custom-if-statements)

It is possible to add similar functionality through custom Directives

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~7 days

Total

4

Last Release

3010d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3773564?v=4)[dijitaltrix](/maintainers/dijitaltrix)[@dijitaltrix](https://github.com/dijitaltrix)

---

Top Contributors

[![ipre-ian](https://avatars.githubusercontent.com/u/35836354?v=4)](https://github.com/ipre-ian "ipre-ian (35 commits)")

---

Tags

phpslimbladetemplateviewrendererscythe

### Embed Badge

![Health badge](/badges/dijitaltrix-scythe-view/health.svg)

```
[![Health](https://phpackages.com/badges/dijitaltrix-scythe-view/health.svg)](https://phpackages.com/packages/dijitaltrix-scythe-view)
```

###  Alternatives

[eftec/bladeone

The standalone version Blade Template Engine from Laravel in a single php file

8259.3M103](/packages/eftec-bladeone)[slim/php-view

Render PHP view scripts into a PSR-7 Response object.

2749.8M101](/packages/slim-php-view)[rubellum/slim-blade-view

Slim Framework 3 view helper built on the Blade component

1822.4k2](/packages/rubellum-slim-blade-view)[eftec/bladeonehtml

The standalone version Blade Template Engine from Laravel in a single php file

1021.6k6](/packages/eftec-bladeonehtml)[hiropeke/slim-blade-view

Slim Framework 3 view helper built on the Blade component

182.0k1](/packages/hiropeke-slim-blade-view)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
