Enhance template placeholder functionality: Updated the TemplateService to support new placeholders for page content, title, and excerpt. Modified related components and views to utilize these placeholders, improving dynamic content rendering. Added special placeholder buttons in the placeholder picker for easier insertion.
This commit is contained in:
@@ -43,7 +43,7 @@ class SectionTemplateForm
|
|||||||
->columnSpanFull()
|
->columnSpanFull()
|
||||||
->helperText(__('section-templates.field_html_content_help'))
|
->helperText(__('section-templates.field_html_content_help'))
|
||||||
->extraAttributes([
|
->extraAttributes([
|
||||||
'style' => 'max-height: 400px;overflow-y: auto;',
|
'style' => 'max-height: 400px;overflow-y: auto;max-width: 100%;',
|
||||||
'data-field-name' => 'html_content',
|
'data-field-name' => 'html_content',
|
||||||
]),
|
]),
|
||||||
|
|
||||||
|
|||||||
@@ -74,7 +74,8 @@ class PageController extends Controller
|
|||||||
|
|
||||||
$renderedHeader = TemplateService::replacePlaceholders(
|
$renderedHeader = TemplateService::replacePlaceholders(
|
||||||
$page->headerTemplate->html_content,
|
$page->headerTemplate->html_content,
|
||||||
$mergedHeaderData
|
$mergedHeaderData,
|
||||||
|
$page
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +89,8 @@ class PageController extends Controller
|
|||||||
|
|
||||||
$renderedFooter = TemplateService::replacePlaceholders(
|
$renderedFooter = TemplateService::replacePlaceholders(
|
||||||
$page->footerTemplate->html_content,
|
$page->footerTemplate->html_content,
|
||||||
$mergedFooterData
|
$mergedFooterData,
|
||||||
|
$page
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,7 +156,8 @@ public function show($slug)
|
|||||||
|
|
||||||
$renderedHeader = TemplateService::replacePlaceholders(
|
$renderedHeader = TemplateService::replacePlaceholders(
|
||||||
$page->headerTemplate->html_content,
|
$page->headerTemplate->html_content,
|
||||||
$mergedHeaderData
|
$mergedHeaderData,
|
||||||
|
$page
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,7 +171,8 @@ public function show($slug)
|
|||||||
|
|
||||||
$renderedFooter = TemplateService::replacePlaceholders(
|
$renderedFooter = TemplateService::replacePlaceholders(
|
||||||
$page->footerTemplate->html_content,
|
$page->footerTemplate->html_content,
|
||||||
$mergedFooterData
|
$mergedFooterData,
|
||||||
|
$page
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -274,9 +274,50 @@ class TemplateService
|
|||||||
* Supports both {text.title} and {{text.title}} formats
|
* Supports both {text.title} and {{text.title}} formats
|
||||||
* Also supports {menu} and {staticMenu} placeholders for menu rendering
|
* Also supports {menu} and {staticMenu} placeholders for menu rendering
|
||||||
* Also supports {custom.component_name} for custom blade components
|
* Also supports {custom.component_name} for custom blade components
|
||||||
|
* Also supports {page.content}, {page.title}, {page.excerpt} for page data
|
||||||
*/
|
*/
|
||||||
public static function replacePlaceholders(string $html, array $data): string
|
public static function replacePlaceholders(string $html, array $data, ?\App\Models\Page $page = null): string
|
||||||
{
|
{
|
||||||
|
// Handle special {page.content} placeholder - Sayfa içeriğini gösterir
|
||||||
|
if (str_contains($html, '{page.content}')) {
|
||||||
|
$pageContent = '';
|
||||||
|
if ($page) {
|
||||||
|
// Translation desteği varsa çeviriyi kullan
|
||||||
|
if (method_exists($page, 'translate')) {
|
||||||
|
$pageContent = $page->translate('content') ?: $page->content;
|
||||||
|
} else {
|
||||||
|
$pageContent = $page->content;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$html = str_replace('{page.content}', $pageContent ?? '', $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle special {page.title} placeholder - Sayfa başlığını gösterir
|
||||||
|
if (str_contains($html, '{page.title}')) {
|
||||||
|
$pageTitle = '';
|
||||||
|
if ($page) {
|
||||||
|
if (method_exists($page, 'translate')) {
|
||||||
|
$pageTitle = $page->translate('title') ?: $page->title;
|
||||||
|
} else {
|
||||||
|
$pageTitle = $page->title;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$html = str_replace('{page.title}', $pageTitle ?? '', $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle special {page.excerpt} placeholder - Sayfa özetini gösterir
|
||||||
|
if (str_contains($html, '{page.excerpt}')) {
|
||||||
|
$pageExcerpt = '';
|
||||||
|
if ($page) {
|
||||||
|
if (method_exists($page, 'translate')) {
|
||||||
|
$pageExcerpt = $page->translate('excerpt') ?: $page->excerpt;
|
||||||
|
} else {
|
||||||
|
$pageExcerpt = $page->excerpt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$html = str_replace('{page.excerpt}', $pageExcerpt ?? '', $html);
|
||||||
|
}
|
||||||
|
|
||||||
// Handle special {menu} placeholder first
|
// Handle special {menu} placeholder first
|
||||||
if (str_contains($html, '{menu}')) {
|
if (str_contains($html, '{menu}')) {
|
||||||
$renderedMenu = \App\Services\MenuService::render();
|
$renderedMenu = \App\Services\MenuService::render();
|
||||||
|
|||||||
@@ -44,7 +44,8 @@ class PageRenderer extends Component
|
|||||||
|
|
||||||
return TemplateService::replacePlaceholders(
|
return TemplateService::replacePlaceholders(
|
||||||
$this->page->headerTemplate->html_content,
|
$this->page->headerTemplate->html_content,
|
||||||
$mergedData
|
$mergedData,
|
||||||
|
$this->page
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +68,8 @@ class PageRenderer extends Component
|
|||||||
|
|
||||||
$output .= TemplateService::replacePlaceholders(
|
$output .= TemplateService::replacePlaceholders(
|
||||||
$section['template']->html_content,
|
$section['template']->html_content,
|
||||||
$mergedData
|
$mergedData,
|
||||||
|
$this->page
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +92,8 @@ class PageRenderer extends Component
|
|||||||
|
|
||||||
return TemplateService::replacePlaceholders(
|
return TemplateService::replacePlaceholders(
|
||||||
$this->page->footerTemplate->html_content,
|
$this->page->footerTemplate->html_content,
|
||||||
$mergedData
|
$mergedData,
|
||||||
|
$this->page
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,6 +105,60 @@
|
|||||||
|
|
||||||
<!-- Placeholder List -->
|
<!-- Placeholder List -->
|
||||||
<div class="overflow-y-auto overflow-x-hidden space-y-4" style="height: 200px; padding: 10px;overflow-y: auto;">
|
<div class="overflow-y-auto overflow-x-hidden space-y-4" style="height: 200px; padding: 10px;overflow-y: auto;">
|
||||||
|
<!-- Special Placeholders Section -->
|
||||||
|
<div class="space-y-2">
|
||||||
|
<h4 class="fi-section-header-heading text-xs font-semibold uppercase tracking-wide">
|
||||||
|
{{ __('placeholder-picker.special_placeholders') }}
|
||||||
|
</h4>
|
||||||
|
<div class="flex flex-wrap gap-2">
|
||||||
|
<x-filament::button
|
||||||
|
size="sm"
|
||||||
|
color="primary"
|
||||||
|
outlined
|
||||||
|
x-on:click="window.insertPlaceholder('{{ $fieldName }}', 'page.content')"
|
||||||
|
x-bind:tooltip="'{{ __('placeholder-picker.click_to_insert') }}'"
|
||||||
|
>
|
||||||
|
<code class="text-xs font-mono">{page.content}</code>
|
||||||
|
</x-filament::button>
|
||||||
|
<x-filament::button
|
||||||
|
size="sm"
|
||||||
|
color="primary"
|
||||||
|
outlined
|
||||||
|
x-on:click="window.insertPlaceholder('{{ $fieldName }}', 'page.title')"
|
||||||
|
x-bind:tooltip="'{{ __('placeholder-picker.click_to_insert') }}'"
|
||||||
|
>
|
||||||
|
<code class="text-xs font-mono">{page.title}</code>
|
||||||
|
</x-filament::button>
|
||||||
|
<x-filament::button
|
||||||
|
size="sm"
|
||||||
|
color="primary"
|
||||||
|
outlined
|
||||||
|
x-on:click="window.insertPlaceholder('{{ $fieldName }}', 'page.excerpt')"
|
||||||
|
x-bind:tooltip="'{{ __('placeholder-picker.click_to_insert') }}'"
|
||||||
|
>
|
||||||
|
<code class="text-xs font-mono">{page.excerpt}</code>
|
||||||
|
</x-filament::button>
|
||||||
|
<x-filament::button
|
||||||
|
size="sm"
|
||||||
|
color="primary"
|
||||||
|
outlined
|
||||||
|
x-on:click="window.insertPlaceholder('{{ $fieldName }}', 'menu')"
|
||||||
|
x-bind:tooltip="'{{ __('placeholder-picker.click_to_insert') }}'"
|
||||||
|
>
|
||||||
|
<code class="text-xs font-mono">{menu}</code>
|
||||||
|
</x-filament::button>
|
||||||
|
<x-filament::button
|
||||||
|
size="sm"
|
||||||
|
color="primary"
|
||||||
|
outlined
|
||||||
|
x-on:click="window.insertPlaceholder('{{ $fieldName }}', 'staticMenu')"
|
||||||
|
x-bind:tooltip="'{{ __('placeholder-picker.click_to_insert') }}'"
|
||||||
|
>
|
||||||
|
<code class="text-xs font-mono">{staticMenu}</code>
|
||||||
|
</x-filament::button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<template x-for="(info, type) in filteredCategories" x-bind:key="type">
|
<template x-for="(info, type) in filteredCategories" x-bind:key="type">
|
||||||
<div class="space-y-2">
|
<div class="space-y-2">
|
||||||
<h4 class="fi-section-header-heading text-xs font-semibold uppercase tracking-wide">
|
<h4 class="fi-section-header-heading text-xs font-semibold uppercase tracking-wide">
|
||||||
@@ -190,6 +244,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
function insertPlaceholder(fieldName, placeholder) {
|
function insertPlaceholder(fieldName, placeholder) {
|
||||||
|
// Placeholder'ı {placeholder} formatında oluştur
|
||||||
const placeholderText = '{' + placeholder + '}';
|
const placeholderText = '{' + placeholder + '}';
|
||||||
|
|
||||||
// Monaco Editor instance'ını bul
|
// Monaco Editor instance'ını bul
|
||||||
|
|||||||
@@ -16,7 +16,8 @@
|
|||||||
@if($section['template'] ?? null)
|
@if($section['template'] ?? null)
|
||||||
{!! \App\Services\TemplateService::replacePlaceholders(
|
{!! \App\Services\TemplateService::replacePlaceholders(
|
||||||
$section['template']->html_content,
|
$section['template']->html_content,
|
||||||
$section['data'] ?? []
|
$section['data'] ?? [],
|
||||||
|
$page ?? null
|
||||||
) !!}
|
) !!}
|
||||||
@endif
|
@endif
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|||||||
@@ -16,7 +16,8 @@
|
|||||||
@if($section['template'] ?? null)
|
@if($section['template'] ?? null)
|
||||||
{!! \App\Services\TemplateService::replacePlaceholders(
|
{!! \App\Services\TemplateService::replacePlaceholders(
|
||||||
$section['template']->html_content,
|
$section['template']->html_content,
|
||||||
$section['data'] ?? []
|
$section['data'] ?? [],
|
||||||
|
$page ?? null
|
||||||
) !!}
|
) !!}
|
||||||
@endif
|
@endif
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|||||||
Reference in New Issue
Block a user