2

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.

0

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I agree this is the best solution all around, but i wanted to have a wordpress style theme system. Unzip a folder and it just works. With this there will need to be 2 folders setup. I could setup an "install" system that will copy the assets from the view folder if they dont exist in the public directory. I was just hoping to have something like wordpress does.
You can use Elixir then. If you use SASS/SCSS or LESS instead of CSS, you can call a elixir(function(mix) { ... }) to get it working, because it's stored under /resources/assets/sass for example, so you can just drop a zip folder in /resources/ and call Elixir. All docs are here: Elixir Laravel 5.1 Official documentation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.