Skip to content

Frontend Templates

Phillip Dornauer edited this page Apr 1, 2026 · 1 revision

Frontend Templates

Marble resolves URL slugs to Items and renders Blade views from resources/views/marble-pages/. The view filename matches the blueprint identifier.

Route Setup

In routes/web.php:

use Marble\Admin\Facades\Marble;

Marble::routes(function ($item) {
    return view(Marble::viewFor($item), ['item' => $item]);
});

If you have custom routes (search, login, etc.), define them before Marble::routes() and set MARBLE_AUTO_ROUTING=false in .env.

View Resolution

For blueprint identifier blog_post, Marble looks for:

  1. resources/views/marble-pages/blog_post.blade.php
  2. resources/views/marble-pages/default.blade.php
  3. Package built-in fallback

Basic Template

@extends('layouts.frontend')

@section('title', $item->name())

@section('content')
    <h1>{{ $item->name() }}</h1>
    {!! $item->value('content') !!}
@endsection

Accessing Fields

{{ $item->value('title') }}                    {{-- Current language --}}
{!! $item->value('content') !!}                {{-- HTML — avoid escaping --}}
{!! nl2br(e($item->value('summary'))) !!}      {{-- Preserve line breaks --}}
{{ $item->value('title', 'de') }}              {{-- Specific language --}}

Navigation

@php $nav = Marble::navigation(); @endphp
@foreach($nav as $navItem)
    <a href="{{ Marble::url($navItem) }}">{{ $navItem->name() }}</a>
    @foreach($navItem->navChildren as $child)
        <a href="{{ Marble::url($child) }}">{{ $child->name() }}</a>
    @endforeach
@endforeach

Breadcrumbs

@php $crumbs = Marble::breadcrumb($item); @endphp
@foreach($crumbs as $crumb)
    @if(!$loop->last)
        <a href="{{ Marble::url($crumb) }}">{{ $crumb->name() }}</a> /
    @else
        {{ $crumb->name() }}
    @endif
@endforeach

Children

@foreach(Marble::children($item, 'blog_post') as $post)
    <a href="{{ Marble::url($post) }}">{{ $post->name() }}</a>
@endforeach

Querying Items

@php
    $posts = Marble::items('blog_post')
        ->published()
        ->orderBy('created_at', 'desc')
        ->paginate(10);
@endphp

@foreach($posts as $post)
    <h2><a href="{{ Marble::url($post) }}">{{ $post->name() }}</a></h2>
@endforeach
{{ $posts->links() }}

Images

@php $img = $item->value('hero_image'); @endphp
@if($img)
    <img src="{{ $img->url(1200, 600) }}" alt="{{ $item->name() }}">
@endif

Related Items

@php $author = $item->value('author'); @endphp
@if($author instanceof \Marble\Admin\Models\Item)
    By <a href="{{ Marble::url($author) }}">{{ $author->name() }}</a>
@endif

Repeater Fields

@foreach($item->value('features') as $feature)
    <h3>{{ $feature['title'] ?? '' }}</h3>
    <p>{{ $feature['description'] ?? '' }}</p>
@endforeach

Site Settings

{{ Marble::settings()?->value('site_name') }}

Portal Authentication

@if(Marble::isPortalAuthenticated())
    Welcome, {{ Marble::portalUser()?->email }}
    <form action="{{ route('marble.portal.logout') }}" method="POST">
        @csrf <button type="submit">Sign out</button>
    </form>
@else
    <a href="{{ route('marble.portal.login') }}">Sign in</a>
@endif

Contact Form

<x-marble::marble-form :item="$item">
    <button type="submit">Send</button>
</x-marble::marble-form>

Marble Debugbar

Set MARBLE_DEBUGBAR=true in .env. A floating debug panel appears on the frontend when an admin is logged in, showing item info, field values, and cache state.

Clone this wiki locally