dougang5993
dougang5993
2018-12-13 18:47
浏览 24
已采纳

Laravel中是否有资产和URL的替代方案?

I am trying to link my css file via asset like:

@if(session()->has('locale'))
    <?php $file_name = "css/".session()->get('locale').'.css'; ?>
    <link href="{{asset('<?php echo $file_name;?>')}}" rel="stylesheet">
@endif

the value $file_name is dr but at source-view is shows like: <link href="{{asset('css/dr.css')}}" rel="stylesheet"> the link address is no correct it must show <link href="http://localhost:8000/css/dr.css" rel="stylesheet"> what should I use instead of asset or url?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • drhrpa2945
    drhrpa2945 2018-12-13 18:52
    已采纳

    the {{ }} will already transform this to php syntax. If you look at storage/framework/views there will be some "compiled" files of the view. There is no need to use <?php echo ... ?>. Just use:

    <link href="{{asset($file_name)}}" rel="stylesheet">
    

    Make sure your view filename is something.blade.php

    点赞 评论

相关推荐