douping3891 2016-09-02 01:57
浏览 28
已采纳

Laravel - 嵌套刀片回声

I am using a blade echo inside of a stylesheet reference in my header section. This is for specifying a CSS for a skin to the site.

The original line is:

<link href="{{ asset("/dist/css/skins/skin-default.min.css"}}" rel="stylesheet" type="text/css\" />

I am grabbing a skin setting per user and want to insert it into that line to change what the user wants as their skin. I have the setting pulled out into a variable from within a view service provider.

$view->with('visualSkin', Auth::user()->visualSkin);

This way I have $visualSkin set when all views are rendered.

How can I insert that into the asset href above and default it to a setting if the user has none set?

I can call the variable or set a default by doing:

{{ $visualSkin or "skin-default" }}

However, how can I inline that section with my asset href? Something like this does not work:

<link href="{{ asset("/dist/css/skins/{{ $visualSkin or "skin-red-trim" }}.min.css"}}" rel="stylesheet" type="text/css\" />

I've also tried some php trickery, but since it's blade formatting when inserting it into php echo, it doesn't get rendered by the blade process.

Can you nest blade echos?
Am I missing some character escaping?

  • 写回答

1条回答 默认 最新

  • douchai7891 2016-09-02 02:25
    关注

    You don't need nesting! Inside blade tags, PHP is running, so you can concatenate strings naturally.

    <link href="{{ asset("/dist/css/skins/" . $visualSkin or "skin-red-trim" . ".min.css")}}" rel="stylesheet" type="text/css\" />
    

    Note that was missing the ) to close the asset( function.


    Using {{ 'something' }} is the same that type: echo 'something'

    So anything that you can do with an echo, you can do on the blade echo tags.

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

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测