framework: @include adding extra space/line break to content

  • Laravel Version: 5.8.7
  • PHP Version: 7.2.5, 7.3.3
  • Database Driver & Version:

Description:

Blade @includes are appending extra white space to the end

Steps To Reproduce:

test/include.blade.php this is only a test

parent.blade.php

<div>@include('test.include')</div>

expected html output:

<div>this is only a test</div>

actual html output:

<div>this is only a test
</div>

In most circumstances, this isn’t really an issue, but in cases where you need to prevent white-space between html elements, it becomes an issue as the extra whitespace creates a gap between them.

In Laravel 5.7.x, the same code returned the expected behavior. Potentially even within an earlier version of 5.8, but I’m not sure.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15 (14 by maintainers)

Commits related to this issue

Most upvoted comments

Hi all, sorry for one more breakage of Blade usage scenario. I’ll start an investigation today and will do my best to come back soon with the possible solution.

Heya, I think this might be related to https://github.com/laravel/framework/pull/27544 which adds an extra linebreak at the end. This got fixed in https://github.com/laravel/framework/pull/27976 which will be released tomorrow. Feel free to report back if tomorrow’s release doesn’t fixes your problem.

However, I fully agree that we should look at how we can look at a way to keep the feature while solving this bug.

👍 We’ll wait to see what @bzixilu says, if there’s another way PHPStorm could parse it.

Is this only a problem when you use an include between html tags? Or also in other ways/usages?

Other ways/usages too. A blade @include() is always appending a newline when rendered. The surrounding <div> tag was only used in the example to better illustrate the problem.