Router w/Static HTML Integration Tutorial
How it works:
- Generate static HTML pages in a subfolder of the site, based on static HTML templates.
- Include a Router to enable:
- Page URLs anywhere in the site
- Redirects defined in CMS
Router w/Static HTML Limitations:
- No Server-side code in pages (unless publish templates are used)
Overview:
The Router integration method:
- Serves static content (images, files) out of a public content folder
- Adds a route to the Laravel application, to serve CMS pages and redirects
The route should be placed at the end of other application routes.
Watch Video Tutorial
Integration:
- In the jsHarmony CMS, on the Sites tab, create a new Site
- Download the jsHarmony Redirects Component and extract into your site's SFTP folder. This contains a "jshcms_redirects.html" component that exports the Redirects as JSON into a file named "jshcms_redirects.json" in the root of the site. A site_config.json file is also included with the "redirect_listing_path" parameter, so that the integration code will be properly generated.
- In the Site Settings, add a Deployment Target:
- Configure the Deployment Target to publish to a public folder in the Laravel application
- Set the URL Prefix to the path prefix for the CMS Content files
- Set the "Override Page URL Prefix" to the path prefix for the CMS Page URLs, if different from the CMS Content path.
For example, if URLs should be root-relative, set the Page URL Prefix to "/"
- Generate the Integration Code:
- In the Deployment Target, click on the "Integration Code" tab
- Select the Environment "PHP - Router" to get the Integration Code
- In your Laravel application, install the "jsharmony-cms-sdk-php" Composer library:
composer require apharmony/jsharmony-cms-sdk-php
- In your Laravel Config file, (ex. config/app.php), add the config from the Integration Code tab in step 4:
'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
- In your Laravel Service Provider (ex. app/Providers/AppServiceProvider.php), initialize the CMS Router:
use apHarmony\jsHarmonyCms\CmsRouter;
...
public function register()
{
$this->app->singleton(CmsRouter::class, function($app){
return new CmsRouter(config('app.cms'));
});
}
- In your Laravel application Router (ex. routes/web.php), add a catchall route, typically at the end of the other application routes, to serve CMS files:
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 Route
Route::get('{url}', function ($url='') {
return app(CmsRouter::class)->serve($url, [
'onPage' => function($router, $fileName){
return response()->file($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', '.*');
- Create a Page Template:
- Local Page Templates can be defined in the CMS, by using the Site's SFTP
:: Creating Page Templates
- Remote Page Templates can be defined in a public subfolder of the Laravel application, and linked to the CMS in the Site Settings "Page Templates" tab.
:: Configuring Remote Page Templates
- If using Remote Page Templates, add the CMS Editor Launcher to each remote page template. Copy the integration code from the Integration Code tab in step 4
<script type="text/javascript" class="removeOnPublish" src="/.jsHarmonyCms/jsHarmonyCmsEditor.js"></script>
<script type="text/javascript" class="removeOnPublish">
jsHarmonyCmsEditor({"access_keys":["****ACCESS_KEY*****"]});
</script>
* Be sure to keep the "removeOnPublish" class in the Launcher script tags, so that the Launcher will not be included in the published pages
* The jsHarmonyCmsEditor.js file is automatically served by the jsHarmonyCmsRouter. The path can be updated in the Router config['cms_clientjs_editor_launcher_path'] parameter
- Add CMS content and publish to the Deployment Target, generating HTML files in the subfolder of the Laravel application
Video Tutorial: