Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Configurable Template Scaffolding #11017

Draft
wants to merge 1 commit into
base: 5.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config/templates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'engine' => 'antlers',
];
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
namespace Statamic\Http\Controllers\CP\Collections;

use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Statamic\Contracts\Entries\Collection as CollectionContract;
use Statamic\Facades\File;
use Statamic\Http\Controllers\CP\CpController;

class ScaffoldCollectionController extends CpController
{
protected array $templateExtensions = [
'antlers' => '.antlers.html',
'blade' => '.blade.php',
];

public function index($collection)
{
$this->authorize('store', CollectionContract::class, __('You are not authorized to scaffold resources.'));
Expand Down Expand Up @@ -37,9 +43,20 @@ public function create(Request $request, $collection)
];
}

private function getTemplateFile($filename)
{
$extension = Arr::get(
$this->templateExtensions,
config('statamic.templates.engine', 'antlers'),
'.antlers.html'
);

return resource_path("views/{$filename}{$extension}");
}

private function makeTemplate($filename)
{
$file = resource_path("views/{$filename}.antlers.html");
$file = $this->getTemplateFile($filename);

// Don't overwrite existing
if (! File::get($file)) {
Expand Down
Loading