du958642589 2018-04-05 14:51
浏览 6
已采纳

在{{}}标记内划分刀片中的行

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
  • 写回答

1条回答 默认 最新

  • doutangguan2460 2018-04-05 16:23
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂