Skip to content

Commit

Permalink
Adding themes default location to the resources/themes
Browse files Browse the repository at this point in the history
  • Loading branch information
tnylea committed Jul 30, 2024
1 parent 7fdb0a5 commit b56a9a3
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ You will want to publish the themes config, and you will now see a new config lo
return [
'themes_folder' => resource_path('views/themes'),
'folder' => resource_path('themes'),
'publish_assets' => true,
'create_tables' => true
];
```

Now, you can choose an alternate location for your themes folder. By default this will be put into the `resources/views` folder; however, you can change that to any location you would like.
Now, you can choose an alternate location for your themes folder. By default this will be put into the `resources` folder; however, you can change that to any location you would like.

> Warning, If you add the themes folder into the `resources/views` folder and you run `php artisan optimize` you may get an error that it cannot find certain components. This is because it will search all the `.blade.php` files inside the views folder. So, this may not be the best place to put your themes. Instead this package will register only the views of the active theme.
Additionally, you can set **publish_assets** to *true* or *false*, if it is set to *true* anytime the themes directory is scanned it will publish the `assets` folder in your theme to the public folder inside a new `themes` folder. Set this to *false* and this will no longer happen.

2 changes: 1 addition & 1 deletion config/themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

return [

'themes_folder' => resource_path('views/themes'),
'folder' => resource_path('views/themes'),
'publish_assets' => true,
'create_tables' => true

Expand Down
2 changes: 1 addition & 1 deletion resources/views/options.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<div class="panel">
<div class="panel-body">

@if(file_exists(config('themes.themes_folder', resource_path('views/themes')) . '/' . $theme->folder . '/options.blade.php'))
@if(file_exists(config('themes.folder', resource_path('views/themes')) . '/' . $theme->folder . '/options.blade.php'))
<?php if (!defined('ACTIVE_THEME_FOLDER')) { define("ACTIVE_THEME_FOLDER", $theme->folder); } ?>
<form action="{{ route('voyager.theme.options', $theme->folder) }}" method="POST" enctype="multipart/form-data">

Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/ThemesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ThemesController extends Controller
private $themes_folder = '';

public function __construct(){
$this->themes_folder = config('themes.themes_folder', resource_path('views/themes'));
$this->themes_folder = config('themes.folder', resource_path('views/themes'));
}

public function index(){
Expand Down
6 changes: 4 additions & 2 deletions src/ThemesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ThemesServiceProvider extends ServiceProvider
*/
public function register()
{
if ( request()->is(config('voyager.prefix')) || request()->is(config('voyager.prefix').'/*') || app()->runningInConsole() ) {
if ( app()->runningInConsole() ) {

try {
DB::connection()->getPdo();
Expand Down Expand Up @@ -66,6 +66,8 @@ public function boot()
{
try{

dd(config('themes.folder'));

$this->loadViewsFrom(__DIR__.'/../resources/views', 'themes');

$theme = '';
Expand All @@ -84,7 +86,7 @@ public function boot()

view()->share('theme', $theme);

$this->themes_folder = config('themes.themes_folder', resource_path('views/themes'));
$this->themes_folder = config('themes.folder', resource_path('views/themes'));

$this->loadDynamicMiddleware($this->themes_folder, $theme);
$this->registerThemeComponents($theme);
Expand Down

0 comments on commit b56a9a3

Please sign in to comment.