繁体   English   中英

Laravel 5.2,file_get_contents与循环所有文件。 如何搭配刀片?

[英]Laravel 5.2, file_get_contents with looping for all files. How with blade?

我想获取resources\\views\\angularTemplates文件夹中文件的全部内容

我之前针对单个文件并使用asset()函数执行了以下操作:

<script type="text/ng-template" id="defult-icons">
  {!! file_get_contents(asset('assets/img/defult_icons.svg')); !!}
</script>

但是现在我要在resources\\views创建整个文件夹

并以循环方式进行每次交互- 当前文件的名称

像这样说:

  @loop('views\angularTemplates', $file_name, $file_content)

    <script type="text/ng-template" id="{!! $file_name !!}">  
        {!! $file_content !!}
    </script>

  @endloop

有办法用刀片的方法吗?

最后,我做到了。 如果有人会:

   <?php

      $path = base_path('resources\views\includes\angular-templates\\');
      $templates = File::allFiles($path);

    ?>

    @foreach ($templates as $template)

        <script type="text/ng-template" id="{!! $template->getBasename() !!}">
          {!! file_get_contents( $path . $template->getBasename() ) !!}
        </script>

    @endforeach

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM