Skip to content

Commit

Permalink
[5.5] Add @includeFirst Blade Directive (#21172)
Browse files Browse the repository at this point in the history
* Add @includeFirst blade directive

* Update CompilesIncludes.php
  • Loading branch information
mattdfloyd authored and taylorotwell committed Sep 13, 2017
1 parent 1d8a3d5 commit bcd1fc4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Illuminate/View/Compilers/Concerns/CompilesIncludes.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,17 @@ protected function compileIncludeWhen($expression)

return "<?php echo \$__env->renderWhen($expression, array_except(get_defined_vars(), array('__data', '__path'))); ?>";
}

/**
* Compile the include-first statements into valid PHP.
*
* @param string $expression
* @return string
*/
protected function compileIncludeFirst($expression)
{
$expression = $this->stripParentheses($expression);

return "<?php echo \$__env->first({$expression}, array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>";
}
}
12 changes: 12 additions & 0 deletions tests/View/Blade/BladeIncludeFirstTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Illuminate\Tests\View\Blade;

class BladeIncludeFirstTest extends AbstractBladeTestCase
{
public function testIncludeFirstsAreCompiled()
{
$this->assertEquals('<?php echo $__env->first(["one", "two"], array_except(get_defined_vars(), array(\'__data\', \'__path\')))->render(); ?>', $this->compiler->compileString('@includeFirst(["one", "two"])'));
$this->assertEquals('<?php echo $__env->first(["one", "two"], ["foo" => "bar"], array_except(get_defined_vars(), array(\'__data\', \'__path\')))->render(); ?>', $this->compiler->compileString('@includeFirst(["one", "two"], ["foo" => "bar"])'));
}
}

0 comments on commit bcd1fc4

Please sign in to comment.