FlexPage-style JSON-driven hybrid theme engine for Laravel 13
snowsoft/nlktheme is a Laravel package for flexpage-style json-driven hybrid theme engine for laravel 13.
It currently has 0 GitHub stars and 351 downloads on Packagist (latest version v0.13).
Install it with composer require snowsoft/nlktheme.
Discover more Laravel packages by snowsoft
or browse all Laravel packages to compare alternatives.
Last updated
Laravel için kapsamlı bir tema yönetim paketi. Birden fazla tema desteği, component sistemı, cache yönetimi ve daha fazlası.
composer require snowsoft/nlktheme
// Controller'da
use Theme;
public function index()
{
return Theme::view('home');
}
// Veya helper ile
return theme()->view('home');
// Belirli tema kullan
Theme::uses('tema2')->layout('main')->view('home');
// Helper ile
theme('tema2', 'main')->view('home');
Bir dosya mevcut temada bulunamazsa, otomatik olarak default temadan yüklenir.
config/theme.php:
'defaultTheme' => 'default',
'useDefaultThemeFallback' => true, // ✅ true yapın
// tema2 temasında header.blade.php yoksa
// otomatik olarak default temasından yükler
Theme::partial('header');
// tema2/views/home.blade.php yoksa
// default/views/home.blade.php arar
Theme::scope('home');
// Partial render
Theme::partial('header', ['title' => 'Welcome']);
// Watch partial (önce temada, sonra app'te ara)
Theme::watchPartial('footer');
// Helper
{!! theme_partial('header') !!}
// Component kaydet
theme()->component('card', 'components.card');
// Component render
theme()->renderComponent('card', ['title' => 'Card Title', 'body' => 'Content']);
// Helper
{!! theme_component('card', ['title' => 'Test']) !!}
@partial('header')
{!! theme_component('card', ['title' => 'Hello']) !!}
// Section başlat
theme()->startSection('sidebar');
echo "Sidebar content";
theme()->stopSection('sidebar');
// Section içeriğini al
$sidebar = theme()->getSection('sidebar');
// Section var mı kontrol et
if (theme()->hasSection('sidebar')) {
echo theme_section('sidebar');
}
{!! theme_section('sidebar', 'Default content') !!}
@if(has_theme_section('sidebar'))
{!! theme_section('sidebar') !!}
@endif
Birden fazla yerde içerik toplamak için:
// Stack başlat
theme()->startStack('scripts');
echo '<script src="plugin1.js"></script>';
theme()->pushStack('scripts');
// Başka yerde
theme()->startStack('scripts');
echo '<script src="plugin2.js"></script>';
theme()->pushStack('scripts');
// Tüm scriptleri al
echo theme()->getStack('scripts');
{!! theme_stack('scripts') !!}
// Asset URL
theme_asset('css/style.css');
// Output: /themes/default/assets/css/style.css
// CSS tag
theme_css('css/style.css');
// Output: <link rel='stylesheet' type='text/css' href='...' media='all'>
// JS tag
theme_js('js/app.js');
// Output: <script type='text/javascript' src='...'></script>
// Image tag
theme_image('images/logo.png', 'Logo', ['class' => 'logo']);
<!DOCTYPE html>
<html>
<head>
{!! theme_css('style.css') !!}
</head>
<body>
<img src="{{ theme_asset('images/logo.png') }}">
{!! theme_js('app.js') !!}
</body>
</html>
Global tema verilerini yönetme:
// Veri set et
theme()->setData('user', $user);
theme()->setMultipleData(['key1' => 'val1', 'key2' => 'val2']);
// Veri al
$user = theme()->getData('user');
$allData = theme()->getAllData();
// Helper
theme_set('key', 'value');
$value = theme_get('key', 'default');
// Tüm cache'i temizle
theme()->clearCache();
// Belirli temanın cache'ini temizle
theme()->clearThemeCache('tema2');
// Temayı yeniden yükle
theme()->reload();
// Helper
theme_cache_clear();
theme_cache_clear('tema2');
// View var mı kontrol et
if (theme()->viewExists('home')) {
return theme()->view('home');
}
// Theme'deki tüm view'ları listele
$views = theme()->getThemeViews();
// Helper
if (has_theme_view('partial.header')) {
{!! theme_partial('partial.header') !!}
}
// Varsa render et
render_if_exists('partial.header', [], 'Default content');
// Metin kısaltma
theme_truncate('Long text here...', 50);
// Output: "Long text here..."
// Time ago
time_ago('2024-01-01 12:00:00');
// Output: "2 hours ago"
// Number format
number_format_short(1000);
// Output: "1K"
number_format_short(1500000);
// Output: "1.5M"
// Active class
active_class('home', 'active');
// Returns: 'active' if current route is 'home'
// Blade'de
<li class="{{ active_class('home') }}">Home</li>
// Widget render
Theme::widget('Menu', ['items' => $menuItems]);
// Blade'de
@widget('Menu', ['items' => $items])
// Region set et
theme()->set('meta', '<meta name="keywords" content="...">');
// Region append
theme()->append('scripts', '<script>...</script>');
// Region prepend
theme()->prepend('styles', '<link>...</link>');
// Region al
$meta = theme()->get('meta', 'default');
// Region var mı kontrol et
if (theme()->has('meta')) {
echo theme()->get('meta');
}
// Blade'de
@get('meta')
@getIfHas('meta')
// Theme yükleme öncesi
Theme::fire('before', $theme);
Theme::fire('asset', $asset);
Theme::fire('beforeRenderTheme', $theme);
Theme::fire('beforeRenderLayout.main', $theme);
Theme::fire('after', $theme);
themes/tema2/config.php:
return [
'events' => [
'before' => function($theme) {
$theme->set('title', 'My Site');
},
'beforeRenderLayout.main' => function($theme) {
$theme->set('description', 'Main layout');
},
],
];
// ThemeServiceProvider.php
public function boot()
{
Theme::composer('*', function($view) {
$view->with('currentUser', auth()->user());
});
}
$content = theme()->compileAndCache(
'Welcome {{ $name }}',
['name' => 'John'],
'welcome_cache',
3600 // TTL
);
$html = theme()->blader('Hello {{ $name }}', ['name' => 'World']);
$compiledPath = theme()->getCompiledPath('theme.tema2.views.home');
themes/
├── default/
│ ├── assets/
│ │ ├── css/
│ │ ├── js/
│ │ └── images/
│ ├── views/
│ │ └── *.blade.php
│ ├── layouts/
│ │ ├── main.blade.php
│ │ └── layout.blade.php
│ ├── partials/
│ │ ├── header.blade.php
│ │ └── footer.blade.php
│ ├── components/
│ │ └── card.blade.php
│ ├── config.php
│ └── theme.json
│
└── tema2/
├── assets/
├── views/
├── layouts/
└── ...
config/theme.php:
return [
'assetUrl' => '/',
'defaultTheme' => 'default',
'useDefaultThemeFallback' => true, // Default theme fallback
'version' => '1.0.0',
'themeDefault' => 'default',
'layoutDefault' => 'layout',
'themeDir' => 'themes',
'themeURL' => 'themes',
'templateCacheEnabled' => true,
'autoReload' => false,
'defaultEngine' => 'blade',
'minify' => false,
'namespaces' => [
'widget' => 'App\Widgets'
],
'events' => [
// Global events
],
];
// Route'da
Route::get('/home', [HomeController::class, 'index'])
->middleware('theme:tema2,main');
// Controller'da
public function index()
{
return theme()->view('home');
}
theme($theme, $layout) - Theme instance altheme_asset($path) - Asset URLtheme_css($path, $media) - CSS tagtheme_js($path, $defer) - JS tagtheme_image($path, $alt, $attrs) - Image tagtheme_partial($view, $args) - Partial rendertheme_component($name, $data) - Component rendertheme_section($section, $default) - Section gettheme_stack($name) - Stack getactive_class($path, $active) - Active classtheme_truncate($text, $limit) - Truncatetime_ago($datetime) - Time agonumber_format_short($number) - Short numbertheme_cache_clear($theme) - Clear cachehas_theme_view($view) - Check view existshas_theme_section($section) - Check sectionrender_if_exists($view, $args, $default) - Render if existstheme_set($key, $value) - Set theme datatheme_get($key, $default) - Get theme datatheme_schema($schema) - Generate JSON-LD schematheme_product_schema($data) - Generate Product schematheme_organization_schema($data) - Generate Organization schematheme_breadcrumb_schema($items) - Generate BreadcrumbList schematheme_article_schema($data) - Generate Article schematheme_video_schema($data) - Generate Video schemaPaket, tema yönetimi için çeşitli Artisan komutları sunar:
# Tema oluştur
php artisan theme:create mytheme
# Temaları listele
php artisan theme:list
# Temayı kopyala
php artisan theme:duplicate default newtheme
# Temayı sil
php artisan theme:destroy oldtheme
# Widget oluştur
php artisan theme:widget ProductSlider
Detaylı kullanım için Artisan Komutları Dokümantasyonu dosyasına bakın.
Paket artık modern frontend framework'leri ve gelişmiş güvenlik özellikleri ile birlikte geliyor:
Detaylı dokümantasyon için:
Sorunlarınız için issue açabilirsiniz.