SwitchBlade: Custom Directives for the Laravel Blade templating engine

Overview

SwitchBlade: Custom Directives for the Laravel Blade templating engine

Latest Stable Version Total Downloads Latest Unstable Version License

Install Via Composer

$ composer require awkwardideas/switchblade

Add to config/app.php

Under Package Service Providers Add

AwkwardIdeas\SwitchBlade\SwitchBladeServiceProvider::class,

Available Directives

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 @caseand 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

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

  • @set(variable, value)
  • @increment(variable)
  • @decrement(variable)

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

  • @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

  • @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

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

If null

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

Not Null

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

Optional Yield

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

File exists

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

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

  • @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.
You might also like...
PHP template engine for native PHP templates

FOIL PHP template engine, for PHP templates. Foil brings all the flexibility and power of modern template engines to native PHP templates. Write simpl

⚡️ Simple and fastly template engine for PHP

EasyTpl ⚡️ Simple and fastly template engine for PHP Features It's simple, lightweight and fastly. No learning costs, syntax like PHP template It is s

Twig Template Engine to Phalcon PHP

Twig Template Engine to Phalcon PHP

Liquid template engine for PHP

Liquid is a PHP port of the Liquid template engine for Ruby, which was written by Tobias Lutke. Although there are many other templating engines for PHP, including Smarty (from which Liquid was partially inspired)

Pug (Jade) template engine for Symfony

Pug-Symfony Pug template engine for Symfony This is the documentation for the ongoing version 3.0. Click here to load the documentation for 2.8 Instal

PHPlater, a simple template engine.

PHPlater A simple PHP template engine that lets PHP do all the logic and then append it to the HTML in the template file. It is set to solve the probl

Laravel package template

REPLACE Simple and flexible package template. Usage Replace all occurances of REPLACE (case sensitive) with the name of the package namespace. E.g. th

Document templates Laravel package is intended for creating/managing user editable document template
Document templates Laravel package is intended for creating/managing user editable document template

Document Templates Introduction Document templates Laravel package is intended for creating/managing user editable document templates, with ability to

Laravel Live Templates for PhpStorm
Laravel Live Templates for PhpStorm

Laravel Live Templates for PhpStorm How to: Go to Preferences | Tools | Settings Repository Add Read-only Source https://github.com/koomai/phpstorm-la

Comments
  • Remove unnecessary files

    Remove unnecessary files

    We'll remove some unnecessary files as well as introduce a .gitignore file to the repo to stop files we don't need from being pushed to version control.

    opened by svenluijten 0
Releases(v1.0.2)
Owner
Awkward Ideas
Awkward Ideas
Experimental ActiveRecord layer on top of Doctrine2 using the Twig templating engine

This is an experiment for building ActiveRecord functionality on top of Doctrine2 using the Twig templating engine. Whether it is called Propel2 or not is irrelevant.

Francois Zaninotto 85 Dec 5, 2022
Provides TemplateView and TwoStepView using PHP as the templating language, with support for partials, sections, and helpers.

Aura View This package provides an implementation of the TemplateView and TwoStepView patterns using PHP itself as the templating language. It support

Aura for PHP 83 Jan 3, 2023
A faster, safer templating library for PHP

Brainy Brainy is a replacement for the popular Smarty templating language. It is a fork from the Smarty 3 trunk. Brainy is still very new and it's lik

Box 66 Jan 3, 2023
The Templating component provides all the tools needed to build any kind of template system.

Templating Component The Templating component provides all the tools needed to build any kind of template system. It provides an infrastructure to loa

Symfony 999 Dec 25, 2022
Simple PHP templating system for user editable templates.

Simple template Simple PHP templating system for user editable templates. Idea Most applications need to render templates that insert safely treated v

Baraja packages 1 Jan 23, 2022
Renders Mithril components to HTML for use in blade templates

Flarum Mithril2Html Uses Chrome Puppeteer via Spatie Browsershot to render Mithril components as static HTML. Follow Browsershot instructions to setup

Clark Winkelmann 3 Nov 13, 2022
View template engine of PHP extracted from Laravel

Blade 【简体中文】 This is a view templating engine which is extracted from Laravel. It's independent without relying on Laravel's Container or any others.

刘小乐 143 Dec 13, 2022
Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.

Smarty 3 template engine smarty.net Documentation For documentation see www.smarty.net/docs/en/ Requirements Smarty can be run with PHP 5.2 to PHP 7.4

Smarty PHP Template Engine 2.1k Jan 1, 2023
☕ Latte: the intuitive and fast template engine for those who want the most secure PHP sites.

Latte: amazing template engine for PHP Introduction Latte is a template engine for PHP which eases your work and ensures the output is protected again

Nette Foundation 898 Dec 25, 2022
PHP Template Attribute Language — template engine for XSS-proof well-formed XHTML and HTML5 pages

PHPTAL - Template Attribute Language for PHP Requirements If you want to use the builtin internationalisation system (I18N), the php-gettext extension

PHPTAL 175 Dec 13, 2022