From b07ee31f3a568c6d537e7a197a93914205bf4ed3 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 22 Mar 2012 22:14:20 -0500 Subject: [PATCH] Added support for Twig style {{ include() }} blade structures that inherit the data from the view. Signed-off-by: Taylor Otwell --- laravel/blade.php | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/laravel/blade.php b/laravel/blade.php index ae5c4c84..c94b3cc3 100644 --- a/laravel/blade.php +++ b/laravel/blade.php @@ -8,6 +8,7 @@ class Blade { * @var array */ protected static $compilers = array( + 'includes', 'echos', 'forelse', 'empty', @@ -85,6 +86,21 @@ public static function compile_string($value) return $value; } + /** + * Rewrites Blade "include" statements to valid PHP. + * + * @param string $value + * @return string + */ + protected static function compile_includes($value) + { + $pattern = '/\{\{(\s*)include(\s*\(.*\))(\s*)\}\}/'; + + $value = preg_replace($pattern, ''; + } + /** * Rewrites Blade echo statements into PHP echo statements. * @@ -115,9 +131,9 @@ protected static function compile_forelse($value) { preg_match('/\$[^\s]*/', $forelse, $variable); - // Once we have extracted the variable being looped against, we cab - // prepend an "if" statmeent to the start of the loop that checks - // that the count of the variable is greater than zero. + // Once we have extracted the variable being looped against, we can prepend + // an "if" statmeent to the start of the loop that checks that the count + // of the variable is greater than zero before looping the data. $if = " 0): ?>"; $search = '/(\s*)@forelse(\s*\(.*\))/'; @@ -126,9 +142,9 @@ protected static function compile_forelse($value) $blade = preg_replace($search, $replace, $forelse); - // Finally, once we have the check prepended to the loop, we will - // replace all instances of this "forelse" structure in the - // content of the view being compiled to Blade syntax. + // Finally, once we have the check prepended to the loop, we will replace + // all instances of this "forelse" structure in the content of the view + // being compiled to Blade syntax using a simple str_replace. $value = str_replace($forelse, $blade, $value); } }