1. Why widget-first?
2. Folder structure
3. theme.json: the theme's passport
{
"name": "Spotlight",
"slug": "spotlight",
"version": "1.1.4",
"namespace": "Spotlight",
"provider": "Spotlight\\SpotlightServiceProvider",
"requires": { "rj_cms": ">=1.8.6", "php": ">=8.2" },
"views": {
"layout": "views/layout.blade.php",
"single_post": "views/single-post.blade.php",
"single_page": "views/single-page.blade.php",
"archive": "views/archive.blade.php"
}
}
4. The ServiceProvider: your theme's entry point
namespace Spotlight;
use Illuminate\Support\ServiceProvider;
use Spotlight\Widgets\SpotlightVideoShowcaseWidget;
class SpotlightServiceProvider extends ServiceProvider
{
public function boot(): void
{
// Tell Laravel where the spotlight:: view namespace lives
$this->loadViewsFrom(__DIR__ . '/../views', 'spotlight');
$this->registerWidgets();
$this->maybeSetupStarterContent();
}
protected function registerWidgets(): void
{
if (!function_exists('rj_add_filter')) return;
rj_add_filter('builder.widgets', function ($existing) {
return array_merge($existing, [
new SpotlightVideoShowcaseWidget(),
// more widgets...
]);
});
}
}
5. Your first widget, step by step
5.1. The PHP class
namespace Spotlight\Widgets;
use App\Widgets\BaseWidget;
class SpotlightVideoShowcaseWidget extends BaseWidget
{
public function id(): string { return 'spotlight-video-showcase'; }
public function name(): string { return __('Spotlight Video Showcase'); }
public function category(): string { return 'spotlight'; }
public function description(): string
{
return __('Display a video inside a sleek browser mockup with a lightbox play button.');
}
public function contexts(): array { return ['page', 'block']; }
public function schema(): array
{
return [
['name' => 'title', 'type' => 'text', 'label' => __('Title'),
'default' => __('See it in action'), 'tab' => 'content'],
['name' => 'video_url', 'type' => 'text', 'label' => __('Video URL (YouTube, Vimeo, or MP4)'),
'default' => '', 'tab' => 'content'],
['name' => 'cover_image', 'type' => 'image', 'label' => __('Cover Image'),
'default' => '', 'tab' => 'content'],
];
}
public function render(array $settings): string
{
$uid = 'vs_' . substr(md5(uniqid('', true)), 0, 8);
return view('spotlight::widgets.video-showcase', compact('settings', 'uid'))->render();
}
}
5.2. The Blade view
@php
$uid = $uid ?? ('vs_' . substr(md5(uniqid('', true)), 0, 8));
$title = $settings['title'] ?? '';
$videoUrl = $settings['video_url'] ?? '';
@endphp
<section class="rj-vs" id="{{ $uid }}">
...
<style>
#{{ $uid }}.rj-vs { /* every rule starts with the uid */ }
</style>
<script>
(function () {
var root = document.getElementById(@js($uid));
if (!root) return;
// logic for this widget only
})();
</script>
</section>
5.3. Three technical lessons from the real project
document.body.appendChild(lightbox);
new IntersectionObserver(function (e) {
root.classList.toggle('rj-idle', !e[0].isIntersecting);
}, { threshold: 0.08 }).observe(root);
#uid.rj-idle *, #uid.rj-idle *::before { animation-play-state: paused !important; }
6. BaseWidget helpers
| Helper | What it does |
|---|---|
defaults() / fullDefaults() |
Collects default values from the schema |
commonStyleSchema() |
Background, shadow, align_self, order fields |
advancedSchema() |
Animation, hover, CSS ID/class |
applyAnimation($html, $settings) |
Wraps the HTML in an rj-animate-* class |
backgroundCss($settings) |
Returns CSS for classic and gradient backgrounds |
boxShadowCss($shadow) |
Maps sm/md/lg/xl to CSS |
linkAttrs($settings, 'link') |
href, target, rel="noopener nofollow" |
iconSvg('arrow-right', 20) |
Built-in SVG icon set |
repeaterItems($settings, 'items') |
Safely turns repeater fields into an array |
escape() / attr() |
htmlspecialchars and an attribute builder |
dimensionCss() / spacingStyle() |
Turns padding/margin values into CSS |
If you build HTML in PHP instead of Blade, run every user-supplied value through escape().
7. The Customizer and layout.blade.php
$cPrimary = rj_theme_mod('primary_color', null, 'colors');
$sanitizeColor = function ($value, $default) {
$value = is_string($value) ? trim($value) : '';
return preg_match('/^#[0-9a-fA-F]{3,8}$/', $value) ? $value : $default;
};
$allowedFonts = ['Inter', 'Figtree', 'Roboto', 'Open Sans', 'Lato', 'Poppins', 'system-ui'];
if (!in_array($fontBody, $allowedFonts, true)) $fontBody = 'Inter';
$fontSizeBase = max(12, min(24, (int) rj_theme_mod('font_size_base', 16, 'typography')));
:root {
--rj-primary: {{ $cPrimary }};
--rj-bg: {{ $cBg }};
--rj-container: {{ $containerWidth }}px;
}
8. Custom page templates
@extends('theme::layout')
@section('content')
<header class="rj-frontend-header">
@if($header) {!! rj_render_template($header) !!} @endif
</header>
<main class="rj-frontend-main">
@if($page)
@if($page->isBuilderMode() && $page->hasBlocks())
{!! rj_render_blocks($page->blocks['blocks'] ?? []) !!}
@elseif(!empty($page->content))
<div class="rj-classic-content">{!! $page->content !!}</div>
@endif
@endif
</main>
<footer class="rj-frontend-footer">
@if($footer) {!! rj_render_template($footer) !!} @endif
</footer>
@endsection
9. The hook system
// Filter: modifies a value and returns it
rj_add_filter('builder.widgets', function ($widgets) {
$widgets[] = new MyWidget();
return $widgets;
}, 10, 1);
// Action: does something, returns nothing
rj_add_action('some.event', function ($arg1, $arg2) {
// ...
}, 10, 2);
10. The starter content mechanism
protected function maybeSetupStarterContent(): void
{
if (!function_exists('rj_get_option') || !function_exists('rj_set_option')) return;
try {
$activeTheme = rj_get_option('active_theme', '');
if ($activeTheme === 'spotlight' && !rj_get_option('spotlight_starter_content_imported')) {
SpotlightStarterContent::run();
rj_set_option('spotlight_starter_content_imported', true);
}
} catch (\Throwable $e) {
logger()->error('Spotlight Starter Content Error: ' . $e->getMessage());
}
}
Things to watch:
11. Publishing your theme
{
"repo": "rj-nexus/spotlight",
"name": "Spotlight",
"author": "rj-nexus",
"version": "1.1.4",
"verified": true,
"category": "general",
"tags": ["dark", "glassmorphism", "ai", "saas", "premium"],
"logo": "https://raw.githubusercontent.com/rj-nexus/spotlight/main/screenshot.png",
"details": {
"description": "A dark, modern, builder-first theme...",
"features": ["20+ custom premium widgets", "Auto-import starter content on activation"]
},
"installation": {
"steps": [
"Download the ZIP from the releases page",
"Go to Admin → Appearance → Themes",
"Upload the ZIP file",
"Click Activate"
]
},
"development": { "requires": "RJ Nexus >= 1.8.6" }
}
For users, installation is:
1
Admin
2
Appearance
3
Themes
4
upload ZIP
5
Comments 0
No comments yet. Be the first to share your thoughts!
Leave a comment