{{}}标签中的刀片线断了(Break lines in blade within {{}} tags)

编程入门 行业动态 更新时间:2024-10-28 12:22:39
{{}}标签中的刀片线断了(Break lines in blade within {{}} tags)

我想将一个换行符放入刀片报告中。 我知道有{!! !!} {!! !!}标签来转义html标签,但在我的情况下,我在{{$row[$colField]}}处有一个很长的字符串,因此它已经在{{ }}标签中。

我尝试它的方式会出现像{{ randome text {!! <br/> !!} }} {{ randome text {!! <br/> !!} }} 。

也许还有其他方法可以做到这一点。

@foreach($fieldList as $field) @if ($header->group == $field->group) <?php $colName = $field->columnname ?> <?php $colField = $field->columnfield; ?> <?php $fieldGroup = $field->group; ?> @if ($colName != $fieldGroup) <span class="titleSpan" style="white-space: nowrap; font-weight: bold">{{ $colName=='Age'?'':$colName.':' }} </span> @endif {{$row[$colField]}}<br> @endif @endforeach

I want to put a line break into a blade report. I know there is the {!! !!} tags to escape the html tags, but in my situation I have a long string coming in at {{$row[$colField]}} so it already within {{ }} tags.

The way I tried it would have appeared like {{ randome text {!! <br/> !!} }}.

Is there any other way to do this perhaps.

@foreach($fieldList as $field) @if ($header->group == $field->group) <?php $colName = $field->columnname ?> <?php $colField = $field->columnfield; ?> <?php $fieldGroup = $field->group; ?> @if ($colName != $fieldGroup) <span class="titleSpan" style="white-space: nowrap; font-weight: bold">{{ $colName=='Age'?'':$colName.':' }} </span> @endif {{$row[$colField]}}<br> @endif @endforeach

最满意答案

大括号刀片标签用于回显值,它们不会执行任何其他操作,并且您无法像在示例中那样将它们嵌套。 您可以在Blade文档中找到有关这些标签的信息 ,但总结如下:

双花括号标签意味着回应这个值并且逃避它,例如:

{{ $row[$colField] }}

编译为:

<?php echo e($row[$colField]); ?>

带有2个感叹号的花括号意味着在不逃避它的情况下回应该值,例如:

{!! $row[$colField] !!}

编译为:

<?php echo $row[$colField]; ?>

如果您希望换行符( $row[$colField] )出现在$row[$colField]的值的某个位置,那么您必须输出之前转换该值。 有一些函数,如nl2br可以用换行符替换新行,所以你可以这样做:

{!! nl2br($row[$colField]) !!}

这将编译为:

<?php echo nl2br($row[$colField]); ?>

所以如果$row[$colField]是:

Hello world This is another line.

然后,该代码将输出:

Hello world</br> This is another line.

这就是说你的问题还不清楚,所以如果这些信息没有帮助,那么请重写你的问题,清楚地告诉你想要达到的目标,例如:包括你的输入的例子和你想要的输出的例子。

The curly brace blade tags are for echoing values, they don't do anything else and you cannot nest them in the way you're trying to in your example. You can find information about these tags in the Blade documentation, but in summary:

The double curly brace tag means echo this value and escape it, e.g:

{{ $row[$colField] }}

compiles to:

<?php echo e($row[$colField]); ?>

A curly brace with 2 exclamation marks means echo this value without escaping it, e.g:

{!! $row[$colField] !!}

compiles to:

<?php echo $row[$colField]; ?>

If you would like for a line break (<br/>) to appear somewhere within the value of $row[$colField] then you must transform that value before outputting it. There are functions, like nl2br that can replace new lines with line breaks, so you could for example do this:

{!! nl2br($row[$colField]) !!}

Which would compile to:

<?php echo nl2br($row[$colField]); ?>

So if the value of $row[$colField] is:

Hello world This is another line.

Then that code would output:

Hello world</br> This is another line.

That said your question is unclear so if this information does not help then please rewrite your question to clearly communicate what you're trying to achieve, i.e: include an example of your input and an example of your desired output.

更多推荐

本文发布于:2023-07-15 19:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1117620.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:刀片   标签   Break   tags   blade

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!