【发布时间】:2019-03-11 08:48:27
【问题描述】:
所以我得到了一个奇怪的结果,我无法理解。这只是 html 在源代码中看起来有多漂亮的问题,但这有点烦人,因为它有时也会不一致地缩进。
这里是layout.blade.php文件,忽略上面大部分的html部分:
</div>
<div class="content">
@yield('content')
</div>
</div>
</body>
</html>
这里是扩展 layout.blade.php 的 index.blade.php:
@extends('layout')
@section('content')
<div class="main-title">
<h1>Developer</h1>
<svg>
<line x1="0" y1="0" x2="300" y2="0" style="stroke:rgb(255,255,255);stroke-width:10" />
</svg>
<h1>Designer</h1>
</div>
@stop
我认为这将与 @yield() 放在相同的缩进级别,因为这就是 django 模板和 laravel 教程中发生的情况。
这就是我得到的:
<div class="content">
<div class="main-title">
<h1>Developer</h1>
<svg>
<line x1="0" y1="0" x2="300" y2="0" style="stroke:rgb(255,255,255);stroke-width:10" />
</svg>
<h1>Designer</h1>
</div>
</div>
</div>
</body>
</html>
如您所见,内容不是在 layout.blade.php 中放置 @yield() 的位置。
查看正在服务的生成的php文件看起来应该没问题:
</div>
<div class="content">
<?php echo $__env->yieldContent('content'); ?>
</div>
</div>
</body>
</html>
从 index.blade.php 生成:
<?php $__env->startSection('content'); ?>
<div class="main-title">
<h1>Developer</h1>
<svg>
<line x1="0" y1="0" x2="300" y2="0" style="stroke:rgb(255,255,255);stroke-width:10" />
</svg>
<h1>Designer</h1>
</div>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layout', \Illuminate\Support\Arr::except(get_defined_vars(), array('__data', '__path')))->render(); ?>
这一切都让我假设提供的 html 将具有适当的制表符间距,但事实并非如此。可能是什么原因?可能有一些配置还是只是刀片的一个怪癖?
【问题讨论】:
-
我现在正在尝试自己解决这个问题!大声笑我想知道它的输出是否基于它在索引刀片文件中的缩进?看看它是否会因此而改变?你的意思是
index.blade.html还是index.blade.php? -
这是一个错误,
index.blade.php是正确的文件。 -
您为什么希望框架为您插入标签?您要求它插入该部分,它会这样做。
-
我想您可以使用 after 中间件查看响应并使用
tidy_parse_string()进行清理。我建议不要在生产站点上这样做。 php.net/manual/en/tidy.parsestring.php
标签: php html laravel laravel-blade