touch
V2EX  ›  PHP

求助一个 laravel5.2 blade 模板的问题

  •  
  •   touch · Feb 15, 2017 · 3598 views
    This topic created in 3552 days ago, the information mentioned may be changed or developed.

    我想定义个可变的 class

    <div class="content@yield('content-class')">
    

    这样不行会直接输出 必须

    <div class="content @yield('content-class')">
    

    中间一个空格 有什么办法可以不空格

    @section('content-class', 'A')
    class=contentA
    
    7 replies  •  2017-02-15 22:52:13 +08:00
    kumakiti
    kumakiti
    Feb 15, 2017
    1
    那就得在传递 content-class 的时候前面加空格了
    touch
    touch
    OP
    Feb 15, 2017
    2
    @kumakiti <div class="content@yield('content-class')"> 这样写的话模板是不会解析
    html 源码就是这样 我是想如果没有设置 content-class 的话 class=content
    设置了就是 contentA
    shoaly
    shoaly
    Feb 15, 2017
    3
    <div class="content{{ $more ? " contentA" : "" }}">
    osinx
    osinx
    Feb 15, 2017
    4
    @yield('content-class', 'contentA')
    touch
    touch
    OP
    Feb 15, 2017
    5
    @osinx 不是设置默认值
    如果这样写的话<div class="content@yield('content-class')"> 在 html 里面查看源码就是默认输入 laravel 没有解析 @yield
    必须在前面<div class="content @yield('content-class')">空格模板才会解析
    但是这样就变成了 class=content A
    Mutoo
    Mutoo
    Feb 15, 2017
    6
    用 @yield 来控制 class ,未免有点小题大作了吧...
    klgd
    klgd
    Feb 15, 2017
    7
    既然是一个 class 名,就把整体 contentA 做 yield 好了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1173 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 16:52 · PVG 00:52 · LAX 08:52 · JFK 11:52
    ♥ Do have faith in what you're doing.