Revisions and Previewing

When using the HasRevisions trait, Twill's UI gives publishers the ability to preview their changes without saving, as well as to preview and compare old revisions.

If you are implementing your site using Laravel routing and Blade templating (ie. traditional server side rendering), you can follow Twill's convention of creating frontend views at resources/views/site and naming them according to their corresponding CRUD module name. When publishers try to preview their changes, Twill will render your frontend view within an iframe, passing the previewed record with it's unsaved changes to your view in the $item variable.

If you want to provide Twill with a custom frontend views path, use the frontend configuration array of your config/twill.php file:

1return [
2 'frontend' => [
3 'views_path' => 'site',
4 ],
5 ...
6];

If you named your frontend view differently than the name of its corresponding module, you can use the $previewView class property of your module's controller:

1<?php
2...
3 
4class ProjectController extends ModuleController
5{
6 protected $moduleName = 'projects';
7 
8 protected $previewView = 'custom-view-name';
9 ...
10}

If you want to provide the previewed view with extra variables or simply to rename the $item variable, you can implement the previewData function in your module's admin controller:

1<?php
2...
3protected function previewData($item)
4{
5 return [
6 'project' => $item,
7 'setting_name' => $settingRepository->byKey('setting_name')
8 ];
9}