PHPackages                             awkwardideas/switchblade - 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. awkwardideas/switchblade

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

awkwardideas/switchblade
========================

Extended blade directives for laravel

v1.0.2(9y ago)102.1k2MITPHPPHP &gt;=5.6.4

Since Mar 1Pushed 9y ago1 watchersCompare

[ Source](https://github.com/awkwardideas/SwitchBlade)[ Packagist](https://packagist.org/packages/awkwardideas/switchblade)[ RSS](/packages/awkwardideas-switchblade/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)DependenciesVersions (5)Used By (0)

SwitchBlade: Custom Directives for the Laravel Blade templating engine
======================================================================

[](#switchblade-custom-directives-for-the-laravel-blade-templating-engine)

[![Latest Stable Version](https://camo.githubusercontent.com/9b79b45856af4ccacf2030bba9fab7e35bc9cca91390052cd5c835c42bb2cc97/68747470733a2f2f706f7365722e707567782e6f72672f61776b7761726469646561732f737769746368626c6164652f762f737461626c65)](https://packagist.org/packages/awkwardideas/switchblade)[![Total Downloads](https://camo.githubusercontent.com/faed00f817427ad021ae218851b2fade6750b96d9d1b67861c06bfe8c11762a7/68747470733a2f2f706f7365722e707567782e6f72672f61776b7761726469646561732f737769746368626c6164652f646f776e6c6f616473)](https://packagist.org/packages/awkwardideas/switchblade)[![Latest Unstable Version](https://camo.githubusercontent.com/86d3f23e3859ac0d7e3c317066b9e2cd61e56b4720db59b99f290b2d6b0911a6/68747470733a2f2f706f7365722e707567782e6f72672f61776b7761726469646561732f737769746368626c6164652f762f756e737461626c65)](https://packagist.org/packages/awkwardideas/switchblade)[![License](https://camo.githubusercontent.com/3bf2fdcb6e686854471b6a7675c0ab227e7630d32f055048b9ccabe0d53f535e/68747470733a2f2f706f7365722e707567782e6f72672f61776b7761726469646561732f737769746368626c6164652f6c6963656e7365)](https://packagist.org/packages/awkwardideas/switchblade)

Install Via Composer
--------------------

[](#install-via-composer)

```
$ composer require awkwardideas/switchblade
```

Add to config/app.php
---------------------

[](#add-to-configappphp)

Under Package Service Providers Add

```
AwkwardIdeas\SwitchBlade\SwitchBladeServiceProvider::class,
```

Available Directives
====================

[](#available-directives)

Switch via Blade
----------------

[](#switch-via-blade)

A php switch statement implemented via blade.

The switch statement is similar to a series of IF statements on the same expression. In many occasions, you may want to compare the same variable (or expression) with many different values, and execute a different piece of code depending on which value it equals to. This is exactly what the switch statement is for.

- `@switch(expression, caseStatement1 [, caseStatement2, caseStatement3...])`
    - This is the blade call to start the switch. It requires the expression and the first case statement. Optionally you can add as many case statements as you would like, which would all execute the code between the start of the switch and the first `@endcase` call.
- `@endcase`
    - Add this to end the case statement. Only one is needed to stop all prior cases.
- `@case(caseStatement1 [, caseStatement2, caseStatement3...])`
    - Add this to start a case statement. Optionally you can add as many case statements as you would like, which would all execute the code between the `@case`and next `@endcase` call.
- `@defaultcase`
    - Add this near the bottom of the switch to handle any variants of the expression which may not have been captured by a case statement. No end case is necessary since it will end with `@endswitch`
- `@endswitch`
    - Add this to end your switch statement

---

Variable Modification
---------------------

[](#variable-modification)

Set, increment or decrement variables without having to go in and out of php.

- `@set(variable, value)`
- `@increment(variable)`
- `@decrement(variable)`

---

Variable Output
---------------

[](#variable-output)

- `@htmlAttribute(value)`
    - Echos the value safe for use in html attributes like id
- `@explode(delimiter, string, index)`
    - Echos the index of the exploded result of the string, split by the delimiter
- `@implode(delimiter, array)`
    - Echos the string result of the array joined by the delimiter

---

Debug Tools
-----------

[](#debug-tools)

- `@dd(variable)`
    - Does a dump and die on the variable
- `@varDump(variable)`
    - Does a dump of the variable
- `@getenv(ENV_VAR_NAME)`
    - Echos the environment variable

---

Other helpful directives
------------------------

[](#other-helpful-directives)

- `@continue`
    - Adds a php continue; tag to skip the rest of the current loop iteration
- `@break`
    - Adds a php break; tag which ends the execution of a for, foreach, do-while or switch structure

### If empty

[](#if-empty)

- `@ifempty(variable)`
    - If count of variable == 0
- `@endifempty`
    - Ends if empty statement

### If null

[](#if-null)

- `@ifnull(variable)`
    - If variable is null
- `@endifnull`
    - Ends if null statement

### Not Null

[](#not-null)

- `@notnull(variable)`
    - If variable is not null
- `@endnotnull`
    - Ends not null statement

### Optional Yield

[](#optional-yield)

- `@optional('section')`
    - Outputs the content wrapped only if the referenced section has value
- `@endoptional`
    - Ends optional output statement

### File exists

[](#file-exists)

- `@iffileexists(filepath)`
    - Tests file path, continuing only if file exists
- `@endiffileexists`
    - Ends file exists condition

### Has Count

[](#has-count)

- `@hascount(variable)`
    - Obtains the count of the variable, continuing if it is greater than 0
- `@endhascount`
    - Ends has count condition

\##Lang Modification

- `@lang(key[, replace, locale])`
    - Modified to pass through to choice of 1, allowing plurals to be put in without having to have all singular usages changed to choice.

\##Bag

- `@bag(variable[,value])`
    - Appends a variable to a bag, or echos the bag as a list

### Init Script

[](#init-script)

- `@initScript([scriptName])`
    - Adds the script name to a bag if a parameter is passed. If no parameter is passed, the contents of the bag are dumped into a javascript window property.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 57.1% 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 ~3 days

Total

4

Last Release

3347d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/771bc8e6daa6dea7b49ed5a97d38e0aa83c2abd0d32a97074d2eebac40383c49?d=identicon)[awkwardideas](/maintainers/awkwardideas)

---

Top Contributors

[![svenluijten](https://avatars.githubusercontent.com/u/11269635?v=4)](https://github.com/svenluijten "svenluijten (4 commits)")[![dachusa](https://avatars.githubusercontent.com/u/1718958?v=4)](https://github.com/dachusa "dachusa (3 commits)")

### Embed Badge

![Health badge](/badges/awkwardideas-switchblade/health.svg)

```
[![Health](https://phpackages.com/badges/awkwardideas-switchblade/health.svg)](https://phpackages.com/packages/awkwardideas-switchblade)
```

###  Alternatives

[mustache/mustache

A Mustache implementation in PHP.

3.3k44.6M291](/packages/mustache-mustache)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[whitecube/nova-flexible-content

Flexible Content &amp; Repeater Fields for Laravel Nova.

8053.0M25](/packages/whitecube-nova-flexible-content)[mopa/bootstrap-bundle

Easy integration of twitters bootstrap into symfony2

7042.9M33](/packages/mopa-bootstrap-bundle)[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3871.2M](/packages/limenius-react-bundle)[nicmart/string-template

StringTemplate is a very simple string template engine for php. I've written it to have a thing like sprintf, but with named and nested substutions.

2101.7M30](/packages/nicmart-string-template)

PHPackages © 2026

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