Created
August 5, 2015 22:17
-
-
Save phroggyy/810f251ebccf3266a717 to your computer and use it in GitHub Desktop.
Declare view-specific variables on the fly with a blade directive. Use @var('variable', 'value') to use. Paste the code from this gist into a service provider.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\Blade::directive('var', function($expression) { | |
$segments = array_map(function($segment) { | |
return trim($segment); | |
}, explode(',', preg_replace("/[\(\)\\\"\']/", '', $expression))); | |
return '<?php $' . $segments[0] . " = '" . $segments[1] . "' ?>"; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment