- Create templates table with name, body, type, title, target, placeholders - Add Template model with applyToPost method for placeholder replacement - Add Livewire Templates/Index component for CRUD operations - Add templates index view with form and table - Add /templates route - Update Posts/Index to support template selection when creating posts - Templates can be applied to pre-fill post form fields Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
107 lines
5.7 KiB
PHP
107 lines
5.7 KiB
PHP
<div>
|
|
<div class="flex justify-between items-center mb-4">
|
|
<h1 class="text-xl font-semibold">Templates</h1>
|
|
<button wire:click="create" class="bg-blue-600 text-white px-4 py-2 rounded">Add Template</button>
|
|
</div>
|
|
|
|
<div class="mb-4 p-3 bg-blue-50 border border-blue-200 text-blue-800 rounded text-sm">
|
|
<strong>Tip:</strong> Use <code>{{placeholder}}</code> syntax in your templates.
|
|
For example: <code>Welcome {{name}} to {{site}}</code>.
|
|
Define placeholders as comma-separated values in the form below.
|
|
</div>
|
|
|
|
<table class="w-full bg-white border border-gray-200 rounded">
|
|
<thead>
|
|
<tr class="text-left border-b border-gray-200">
|
|
<th class="p-3">Name</th>
|
|
<th class="p-3">Type</th>
|
|
<th class="p-3">Preview</th>
|
|
<th class="p-3">Placeholders</th>
|
|
<th class="p-3"></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach ($templates as $template)
|
|
<tr wire:key="template-{{ $template->id }}" class="border-b border-gray-100">
|
|
<td class="p-3 font-medium">{{ $template->name }}</td>
|
|
<td class="p-3">{{ $template->type ? ucfirst($template->type) : '-' }}</td>
|
|
<td class="p-3 text-sm text-gray-600">
|
|
{{ Str::limit($template->body ?? $template->title ?? '', 50) }}
|
|
</td>
|
|
<td class="p-3">
|
|
@if ($template->placeholders)
|
|
<span class="text-xs bg-gray-100 px-2 py-1 rounded">
|
|
{{ implode(', ', $template->placeholders) }}
|
|
</span>
|
|
@else
|
|
<span class="text-gray-400">-</span>
|
|
@endif
|
|
</td>
|
|
<td class="p-3 text-right space-x-2">
|
|
<button wire:click="edit({{ $template->id }})" class="text-blue-600">Edit</button>
|
|
<button wire:click="delete({{ $template->id }})" wire:confirm="Delete this template?" class="text-red-600">Delete</button>
|
|
</td>
|
|
</tr>
|
|
@endforeach
|
|
</tbody>
|
|
</table>
|
|
|
|
@if ($showForm)
|
|
<div class="fixed inset-0 bg-black/30 flex items-center justify-center">
|
|
<div class="bg-white p-6 rounded w-full max-w-md space-y-4 max-h-[90vh] overflow-y-auto">
|
|
<h2 class="text-lg font-semibold">{{ $editingId ? 'Edit Template' : 'Add Template' }}</h2>
|
|
|
|
<div>
|
|
<label class="block text-sm font-medium">Name <span class="text-red-500">*</span></label>
|
|
<input type="text" wire:model="name" class="w-full border rounded p-2" placeholder="e.g., Blog Post Intro">
|
|
@error('name') <span class="text-red-600 text-sm">{{ $message }}</span> @enderror
|
|
</div>
|
|
|
|
<div>
|
|
<label class="block text-sm font-medium">Type (optional)</label>
|
|
<select wire:model="type" class="w-full border rounded p-2">
|
|
<option value="">Any type</option>
|
|
@foreach ($types as $t)
|
|
<option value="{{ $t }}">{{ ucfirst($t) }}</option>
|
|
@endforeach
|
|
</select>
|
|
@error('type') <span class="text-red-600 text-sm">{{ $message }}</span> @enderror
|
|
</div>
|
|
|
|
<div>
|
|
<label class="block text-sm font-medium">Title (optional)</label>
|
|
<input type="text" wire:model="title" class="w-full border rounded p-2" placeholder="Post title template">
|
|
@error('title') <span class="text-red-600 text-sm">{{ $message }}</span> @enderror
|
|
</div>
|
|
|
|
<div>
|
|
<label class="block text-sm font-medium">Body <span class="text-red-500">*</span></label>
|
|
<textarea wire:model="body" rows="6" class="w-full border rounded p-2 font-mono text-sm" placeholder="Your post content template... Use {{placeholder}} syntax"></textarea>
|
|
@error('body') <span class="text-red-600 text-sm">{{ $message }}</span> @enderror
|
|
</div>
|
|
|
|
<div>
|
|
<label class="block text-sm font-medium">Target (optional)</label>
|
|
<input type="text" wire:model="target" class="w-full border rounded p-2" placeholder="e.g., programming, my-blog-category">
|
|
<p class="text-xs text-gray-500 mt-1">For Reddit: subreddit name. For WordPress: category or tag.</p>
|
|
@error('target') <span class="text-red-600 text-sm">{{ $message }}</span> @enderror
|
|
</div>
|
|
|
|
<div>
|
|
<label class="block text-sm font-medium">Placeholders (comma-separated, optional)</label>
|
|
<input type="text" wire:model="placeholders" class="w-full border rounded p-2" placeholder="e.g., name, site, date">
|
|
<p class="text-xs text-gray-500 mt-1">
|
|
Define placeholders like <code>{{name}}</code>, <code>{{site}}</code> that can be replaced when creating a post.
|
|
</p>
|
|
@error('placeholders') <span class="text-red-600 text-sm">{{ $message }}</span> @enderror
|
|
</div>
|
|
|
|
<div class="flex justify-end gap-2">
|
|
<button wire:click="$set('showForm', false)" class="px-4 py-2">Cancel</button>
|
|
<button wire:click="save" class="bg-blue-600 text-white px-4 py-2 rounded">Save</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@endif
|
|
</div>
|