Enhance placeholder functionality: Updated TemplateService to support 'setting' placeholders, allowing dynamic retrieval of settings values. Modified the placeholder picker to include setting types and added localization for new placeholder types in both English and Turkish. Improved site layout by integrating settings for favicon and custom CSS.

This commit is contained in:
Ümit Tunç
2025-11-05 17:18:02 -03:00
parent 27e1846aec
commit 920502c5d3
5 changed files with 62 additions and 29 deletions
+38 -26
View File
@@ -384,37 +384,49 @@ class TemplateService
// Replace each placeholder
foreach ($placeholders as $placeholder) {
// Try to find the value in data with various key formats
$value = null;
// Extract type from placeholder
$parts = explode('.', $placeholder);
$type = $parts[0] ?? null;
$field = $parts[1] ?? null;
// 1. Try exact match (text.title)
if (isset($data[$placeholder])) {
$value = $data[$placeholder];
}
// 2. Try with section_data prefix (section_data.text.title)
elseif (isset($data["section_data.{$placeholder}"])) {
$value = $data["section_data.{$placeholder}"];
}
// 3. Try nested array access (data['section_data']['text.title'] or data['text']['title'])
else {
$parts = explode('.', $placeholder);
if (count($parts) === 2) {
[$type, $field] = $parts;
// Try nested: data['section_data'][$type][$field]
if (isset($data['section_data'][$type][$field])) {
$value = $data['section_data'][$type][$field];
}
// Try nested: data[$type][$field]
elseif (isset($data[$type][$field])) {
$value = $data[$type][$field];
// Handle setting.* placeholders - get value from Setting model
if ($type === 'setting' && $field) {
$value = setting($field, '');
// Get setting type to determine if it's a file/image
$settingModel = \App\Models\Setting::where('key', $field)->where('is_active', true)->first();
if ($settingModel && in_array($settingModel->type, ['file', 'image'])) {
// For file/image settings, use file type for formatting
$type = 'file';
}
} else {
// Try to find the value in data with various key formats
$value = null;
// 1. Try exact match (text.title)
if (isset($data[$placeholder])) {
$value = $data[$placeholder];
}
// 2. Try with section_data prefix (section_data.text.title)
elseif (isset($data["section_data.{$placeholder}"])) {
$value = $data["section_data.{$placeholder}"];
}
// 3. Try nested array access (data['section_data']['text.title'] or data['text']['title'])
else {
if (count($parts) === 2) {
[$type, $field] = $parts;
// Try nested: data['section_data'][$type][$field]
if (isset($data['section_data'][$type][$field])) {
$value = $data['section_data'][$type][$field];
}
// Try nested: data[$type][$field]
elseif (isset($data[$type][$field])) {
$value = $data[$type][$field];
}
}
}
}
// Extract type from placeholder to determine if it's a file/image
$parts = explode('.', $placeholder);
$type = $parts[0] ?? null;
// Handle different value types
if (is_array($value)) {
// Handle arrays (e.g., multiple images)
+1
View File
@@ -32,6 +32,7 @@ return [
'type_toggle' => 'Toggle',
'type_color' => 'Color',
'type_tags' => 'Tags',
'type_setting' => 'Setting',
'type_custom' => 'Custom',
];
+1
View File
@@ -32,6 +32,7 @@ return [
'type_toggle' => 'Aç/Kapa',
'type_color' => 'Renk',
'type_tags' => 'Etiketler',
'type_setting' => 'Ayar',
'type_custom' => 'Özel',
];
@@ -1,7 +1,20 @@
@php
// Setting key'lerini veritabanından al (aktif ve public olanlar)
$settingKeys = \App\Models\Setting::where('is_active', true)
->where('is_public', true)
->orderBy('key')
->pluck('key')
->toArray();
// Eğer setting yoksa, yaygın örnekleri kullan
if (empty($settingKeys)) {
$settingKeys = ['site_name', 'site_description', 'contact_email', 'contact_phone', 'site_url', 'copyright_text', 'seo_meta_title', 'seo_meta_description'];
}
// Desteklenen placeholder tipleri ve açıklamaları
$placeholderTypes = [
'special' => ['label' => __('placeholder-picker.special_placeholders'), 'examples' => ['page.content', 'page.title', 'page.excerpt', 'menu', 'staticMenu']],
'setting' => ['label' => __('placeholder-picker.type_setting'), 'examples' => array_slice($settingKeys, 0, 15)], // İlk 15 setting'i göster
'text' => ['label' => __('placeholder-picker.type_text'), 'examples' => ['company_name', 'title', 'description', 'subtitle']],
'email' => ['label' => __('placeholder-picker.type_email'), 'examples' => ['contact', 'support', 'info', 'sales']],
'url' => ['label' => __('placeholder-picker.type_url'), 'examples' => ['website', 'facebook', 'twitter', 'linkedin']],
+9 -3
View File
@@ -1,3 +1,7 @@
<?php
$favicon_path = setting('site_favicon');
?>
<!doctype html>
<html lang="{{ app()->getLocale() }}">
<head>
@@ -5,15 +9,17 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ setting('seo_meta_title') }} - {{ $meta['title'] ?? ($settings->default_meta_title ?? config('app.name')) }}</title>
<meta name="description" content="{{ $meta['description'] ?? ($settings->default_meta_description ?? '') }}">
<link rel="icon" href="{{ $settings?->favicon_path ? asset($settings->favicon_path) : asset('assets/img/favicon.ico') }}">
<meta name="description" content="{{ $meta['description'] ?? (setting('seo_meta_description') ?? '') }}">
<link rel="icon" href="{{ asset('storage/' . $favicon_path) }}">
<link rel="stylesheet" href="{{ asset('html/style.css') }}">
<link rel="stylesheet" type="text/css" href="{{ asset('assets/fonts/unicons/unicons.css') }}">
<link rel="stylesheet" href="{{ asset('assets/css/plugins.css') }}">
<link rel="stylesheet" href="{{ asset('assets/css/colors/grape.css') }}">
<link rel="preload" href="{{ asset('assets/css/fonts/urbanist.css') }}" as="style" onload="this.rel='stylesheet'">
<style>
<?php echo setting('custom_css') ?>
</style>
</head>
<body>