Skip to content

[12.x] Add @blank and @filled Blade directives #56192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,48 @@ protected function compileEndIsset()
return '<?php endif; ?>';
}

/**
* Compile the if-blank statements into valid PHP.
*
* @param string $expression
* @return string
*/
protected function compileBlank($expression)
{
return "<?php if(blank{$expression}): ?>";
}

/**
* Compile the end-blank statements into valid PHP.
*
* @return string
*/
protected function compileEndBlank()
{
return '<?php endif; ?>';
}

/**
* Compile the if-filled statements into valid PHP.
*
* @param string $expression
* @return string
*/
protected function compileFilled($expression)
{
return "<?php if(filled{$expression}): ?>";
}

/**
* Compile the end-filled statements into valid PHP.
*
* @return string
*/
protected function compileEndFilled()
{
return '<?php endif; ?>';
}

/**
* Compile the switch statements into valid PHP.
*
Expand Down
28 changes: 28 additions & 0 deletions tests/View/Blade/BladeIfBlankFilledStatementsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Illuminate\Tests\View\Blade;

class BladeIfBlankFilledStatementsTest extends AbstractBladeTestCase
{
public function testBlankStatementsAreCompiled()
{
$string = '@blank ($test)
breeze
@endblank';
$expected = '<?php if(blank($test)): ?>
breeze
<?php endif; ?>';
$this->assertEquals($expected, $this->compiler->compileString($string));
}

public function testFilledStatementsAreCompiled()
{
$string = '@filled ($test)
breeze
@endfilled';
$expected = '<?php if(filled($test)): ?>
breeze
<?php endif; ?>';
$this->assertEquals($expected, $this->compiler->compileString($string));
}
}