How it works:
Overview:
The Router integration method:
The route should be placed at the end of other application routes.
Integration:
composer require apharmony/jsharmony-cms-sdk-php
'cms' => [
"redirect_listing_path" => "jshcms_redirects.json",
"cms_server_urls" => ["https://cms.example.com/"],
"content_path" => $_SERVER['DOCUMENT_ROOT']."/path/to/published_files"
],
* Be sure to update the "content_path" property to match the CMS files publish folder in your Laravel application
use apHarmony\jsHarmonyCms\CmsRouter;
...
public function register()
{
$this->app->singleton(CmsRouter::class, function($app){
return new CmsRouter(config('app.cms'));
});
}
use apHarmony\jsHarmonyCms\CmsRouter;
...
//Template Route, for creating and editing CMS pages
Route::view('/path/to/template/view.blade.php', 'template.name', ['cmsPage' => app(CmsRouter::class)->getPlaceholder()]);
//CMS Catchall Route, for rendering CMS content to the end-user
Route::get('{url}', function ($url='') {
return app(CmsRouter::class)->serve($url, [
'onPage' => function($router, $fileName){
return view('/path/to/template/view.blade.php', ['cmsPage' => app(CmsRouter::class)->getPageFromFile($fileName)]);
},
'on301' => function($router, $url){
return redirect($url, 301);
},
'on302' => function($router, $url){
return redirect($url, 302);
},
'onPassthru' => function($router, $url){
$passthru = $router->passthru($url);
return response($passthru->content, $passthru->http_code)->header('Content-Type', $passthru->content_type);
},
'on404' => function($route){
abort(404);
},
]);
})->where('url', '.*');
{
"templates":{ "publish":"format:json" }
}
{!! $cmsPage->editorScript !!}
<html>
<head>
@if($cmsPage->seo->title)
<title>{{ $cmsPage->seo->title }}</title>
@endif
@if($cmsPage->seo->keywords)
<meta name="keywords" content="{{ $cmsPage->seo->keywords }}" />
@endif
@if($cmsPage->seo->metadesc)
<meta name="description" content="{{ $cmsPage->seo->metadesc }}" />
@endif
@if($cmsPage->seo->canonical_url)
<link rel="canonical" href="{{ $cmsPage->seo->canonical_url }}" />
@endif
@if($cmsPage->css)
<style type="text/css">{!! $cmsPage->css !!}</style>
@endif
@if($cmsPage->js)
<script type="text/javascript">{!! $cmsPage->js !!}</script>
@endif
{!! $cmsPage->header !!}
{!! $cmsPage->editorScript !!}
</head>
<body>
<h1 cms-title>{{ $cmsPage->title }}</h1>
<div cms-content-editor="page.content.body">{!! $cmsPage->content->body !!}</div>
{!! $cmsPage->footer !!}
</body>
</html>
<!-- Page Template Config -->
<script type="text/cms-page-config">
{
"default_content": { "body": "Default Page Content" },
"properties": {
"fields": [
{ "name": "showTitle", "caption": "Show Title", "control": "checkbox", "default": "Y", "controlparams": { "value_true": "Y", "value_false": "N" } },
{ "name": "containerClass", "caption": "Container CSS Class" },
{ "name": "containerStyle", "caption": "Container CSS Style" },
]
}
}
</script>
<!-- Static Page Component -->
<div cms-component="breadcrumbs" cms-component-content="breadcrumbs">{!! $cmsPage->content->breadcrumbs !!}</div>
<!-- onRender / showIf -->
@if($cmsPage->properties->showTitle!='N')
<h1 cms-title cms-onRender="showIf(page.properties.showTitle!='N');">{{ $cmsPage->title }}</h1>
@endif
<!-- onRender / addClass -->
<div cms-onRender="addClass(page.properties.containerClass);" class="{{ $cmsPage->properties->containerClass }}"></div>
<!-- onRender / addStyle -->
<div cms-onRender="addStyle(page.properties.containerStyle);" style="{{ $cmsPage->properties->containerStyle }}"></div>
Video Tutorial: