PHP code example of snowsoft / nlktheme

1. Go to this page and download the library: Download snowsoft/nlktheme library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

snowsoft / nlktheme example snippets


// 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');

'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']) !!}

// 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');
}

// 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');

// 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']);

// 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);

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');

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');
}
blade
@partial('header')
{!! theme_component('card', ['title' => 'Hello']) !!}
blade
{!! theme_stack('scripts') !!}

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/
    └── ...
bash
# 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