Skip to content

Commit

Permalink
Updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Chad Haney committed Mar 1, 2017
1 parent e943738 commit f36e16a
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 3 deletions.
81 changes: 79 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,84 @@ Under Package Service Providers Add

AwkwardIdeas\SwitchBlade\SwitchBladeServiceProvider::class,

## Code use

@htmlAttribute($foo->bar)
# 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 ```@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
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)```
* Echos 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

### 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
2 changes: 1 addition & 1 deletion src/Directive.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public static function AddCustomDirectives()
// Add @ifempty for Loops
Blade::directive('ifempty', function($expression)
{
return "<?php if(count$expression == 0): ?>";
return "<?php if(count($expression) == 0): ?>";
});

// Add @endifempty for Loops
Expand Down

0 comments on commit f36e16a

Please sign in to comment.