Templates and View Data
Every theme template receives a rich, pre-assembled set of variables — the content, site settings, navigation, media and SEO data. This article is the reference for that data and for the rendering rules templates should follow.
How a template is chosen
For content of type page on a site with theme mytheme, Laravix renders themes.mytheme::page.show. If that view doesn't exist, it falls back to themes.mytheme::default. The same convention applies to every content type, including plugin types.
Available variables
Assembled by Laravix\Cms\Services\PageDataBuilder and the CMS controller:
| Variable | Type | Contents |
|---|---|---|
$content |
Content |
The content being rendered, with fields and taxonomies loaded |
$site |
Site |
The current site |
$seo |
array |
title, description, og_image_url, noindex, canonical — with content-over-settings fallbacks already applied |
$settings |
Collection |
All site settings as key ⇒ value |
$navigations |
array |
Header/footer menu items, already localized for the current language |
$navDesign |
array |
The design values from the navigation Design tabs |
$logoMedia, $faviconMedia |
?Media |
The logo and favicon from settings, resolved to models |
$mediaMap |
Collection |
id ⇒ Media map of every media referenced by the page |
$navPages |
Collection |
Published pages/archives of the current locale (id, title, slug, is_homepage) — for building simple menus |
$archivePosts |
?Collection |
On archive content only: published posts, newest first |
$grapesjsHtml |
?string |
The visual builder's HTML, already hydrated (post lists filled in, plugin hydrators applied) |
$defaultLocale, $currentLocale |
string |
Locale codes |
$alternates |
Collection |
locale ⇒ absolute URL of published translations (for hreflang) |
$systemFieldKeys |
array |
Keys of code-registered fields — handy to separate them from ad-hoc fields |
Working with media
Media models expose $media->url (the original) and $media->variantUrl(ImageVariant::LARGE) for resized variants (THUMBNAIL, MEDIUM, LARGE, OG, FAVICON, FULL — see Laravix\Cms\Enums\ImageVariant). Always render the smallest variant that fits the slot.
Working with fields
@php $fields = $content->fields->pluck('value', 'key'); @endphp
{{ $fields->get('excerpt') }}
Rendering builder content
Content designed in the visual builder arrives as $grapesjsHtml. Content built from classic blocks arrives as the $content->blocks array. The core ships a partial that handles both, including the JavaScript that sliders, tabs, countdowns and custom code blocks need:
@include('laravix::cms.builder-content')
The default theme's page/show.blade.php does exactly this when builder content exists, and falls back to a plain title-and-fields layout otherwise. If you render blocks yourself instead, each entry of $content->blocks is ['type' => ..., 'data' => [...]] and maps to your theme view blocks/{type}.blade.php, which receives the block's data plus $mediaMap.
URLs and languages
Build links to other content with $content->path($defaultLocale) — it handles the homepage, route prefixes and locale prefixes. In layouts, emit alternates:
@foreach ($alternates as $altLocale => $altUrl)
<link rel="alternate" hreflang="{{ $altLocale }}" href="{{ $altUrl }}">
@endforeach
SEO contract
Layouts should honor the $seo array: put $seo['title'] in <title>, output the description and canonical link, emit noindex,nofollow robots meta when $seo['noindex'] is true, and use $seo['og_image_url'] for Open Graph. The default theme's layouts/app.blade.php is a complete reference implementation, including Open Graph, Twitter cards and JSON-LD.