Mainstay GitHub
All docs

The Content tab

Editing a page as the site draws it: text typed in place, blocks added, moved and nested.

An entry of a type with a page has two tabs. Details is its form, the title first. Content is the page itself: the <main> of your own view, drawn from the form as it stands, unsaved changes included, with your site's stylesheets and scripts. The header, menu and footer around it are left out, since they are the layout and not this entry.

What an editor does there

  • Types a heading, a paragraph or a block's text field where it shows on the page.

  • Adds a block from the Add block dialog, which previews each one with its example, or from the / menu.

  • Drags a block to another place, or into a block that holds others.

  • Opens a block's fields and images in a dialog beside it, from a toolbar floating by the selected block.

Save draft and Publish save what the tab holds, as they do for the Details tab.

What your view has to do

Print the content in an element of its own. The editor takes over the element the content is printed in, so it must hold the content and nothing else:

resources/views/page.blade.php
<x-layout :title="$entry->title">
    <h1>{{ $entry->title }}</h1>
    <div class="prose">{{ $entry->content }}</div>
</x-layout>

A view that prints its content beside other things in one element is shown read-only, and one that does not print it at all says there is nothing to edit; the content's raw form stays in Details either way.

The editor's styles

Rich text fields elsewhere in the admin are drawn in your site's typography too, once you name the stylesheets and the class your content sits in, in a service provider's boot():

Mainstay::editorStyles(['/css/site.css'], class: 'prose');

Without it they use the admin's own typography.

Blocks that behave in the editor

Your site's script runs on the Content tab as it does on the page. A script that hides things until it runs, tabs or a carousel, should leave every part showing when it runs inside the editor, which it can tell by the content element's JSON script, script[data-mainstay-content], being there when the page loads. In a block's view, Mainstay::marking() says the same.

Only a type with a #[Route] has a Content tab: without a page there is nothing to draw the content on, so its content is edited as text in Details.