duanhuancong1969 2015-11-18 10:35
浏览 330

在Laravel 5中从公共文件夹外部提供CSS和JS

I understand this sort of breaks the structured point of Laravel, but there is method to my madness. I plan on using a single install of laravel to host several websites that are database driven. At the moment all of the sites share the same layout and I have a system to store some custom CSS in the DB to give each site a different color scheme. I want to change this so they can use completely different views. So site A loads views/theme1/app.blade.php and site B loads views/theme2/app.blade.php.

I have implemented this by using the following to return a view.

$theme = getDomainThemeName();
return view($theme.'/home');

This is also working, but i am now left with the task of dynamically loading the assets. I am using bootstrap the generate the themes and making a few tweaks to the HTML to create the app.blade.php file. I have 2 potential solutions to this but i would much rather a way to server the css files from the views directory. This means the following mapping.

http://website.com/css/style.css => /resources/views/theme1/css/style.css

Can something like this be done? Another option would be to use php to read the css file and insert it into the app using a yield. It works, but it means i cant use browser caching to cache the assets. I was also thinking i could just create sub directories in the public folder. public/theme1/css/style.css. This makes the most logical sense, but it means i have to fragment the theme system. Id like to be able to unzip a theme in the views directory and it just works.

I am using Laravel 5, i have root access to the server too. Running PHP 5.4 on centos 7.

  • 写回答

1条回答 默认 最新

  • duanli0453 2015-11-18 11:15
    关注

    I think the best approach is having next structure:

    /public/css/style.css
    /public/css/theme1/custom1.css
    /resources/views/common.blade.php
    /resources/views/theme1/main.blade.php
    

    And then loading conditionally with php each site theme. It may not be any trouble with caching.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog