Standalone Page Integration Tutorial

How it works:

  • Add CMS content to an existing page in the site
  • Generate a JSON object for that page on publish
  • On page view:
    • Load the JSON object and render it in a server-side template


Standalone Page Limitations:

  • Standalone pages need to be configured one-at-a-time in the CMS


Overview:

Standalone Integration can be used to add editable CMS content areas to existing individual pages in an application.  This can be used together with, or apart from, a site with a Router Integration.


Integration:

  1. In the jsHarmony CMS, on the Sites tab, create a new Site

  2. In the Site Settings, add a Deployment Target:
    1. Configure the Deployment Target to publish to a public folder in the PHP application
    2. Set the URL Prefix to the path prefix for the CMS Content files

  3. Generate the Integration Code:
    1. In the Deployment Target, click on the "Integration Code" tab
    2. Select the Environment "PHP - Standalone" to get the Integration Code

  4. In your PHP application, install the "jsharmony-cms-sdk-php" Composer library:
    composer require apharmony/jsharmony-cms-sdk-php

    * Alternatively, the SDK can be downloaded directory from the Github jsharmony-cms-sdk-php project.

  5. In your PHP standalone page,  initialize the CMS Router using the Integration Code from step 3, and add code to load the CMS content for that page: 
    // If not already included in your application, auto-load Composer
    require_once __DIR__.'/vendor/autoload.php';
    
    // Initialize the jsHarmony CMS Router
    use apHarmony\jsHarmonyCms\CmsRouter;
    $cmsRouter = new CmsRouter([
        "redirect_listing_path" => "jshcms_redirects.json",
        "cms_server_urls" => ["https://localhost:8081/"],
        "content_path" => $_SERVER['DOCUMENT_ROOT']."/path/to/published_files"
    ]);
    
    // Get the CMS content for this page
    $page = $cmsRouter->getStandalone();

    * Be sure to update the "content_path" property to match the CMS files publish folder in your PHP application

  6. In the CMS, add the standalone page to the Sitemap:
    1. On the Pages tab, add a new page
    2. Set the Template to "<Standalone>"
    3. Set the Template Path to the full URL of the standalone page

  7. Add the Editor Launcher script to the head tag of the standalone page:
    <?=$page->editorScript?>
  8. Define the editable content areas in the standalone page, using the Page Template attributes ("cms-title", "cms-content-editor").

    * After this step, the standalone page should be editable from the CMS.

  9. Render the CMS Content in the standalone page using the "$page" object passed from step 5.  Any of the following page properties can be used:
    <html>
    <head>
      <?php if($page->seo->title){ ?><title><?=htmlspecialchars($page->seo->title)?></title><?php } ?>
      <?php if($page->seo->keywords){ ?><meta name="keywords" content="<?=htmlspecialchars($page->seo->keywords)?>" /><?php } ?>
      <?php if($page->seo->metadesc){ ?><meta name="description" content="<?=htmlspecialchars($page->seo->metadesc)?>" /><?php } ?>
      <?php if($page->seo->canonical_url){ ?><link rel="canonical" href="<?=htmlspecialchars($page->seo->canonical_url)?>" /><?php } ?>
      <?php if($page->css){ ?><style type="text/css"><?=$page->css?></style><?php } ?>
      <?php if($page->js){ ?><script type="text/javascript"><?=$page->js?></script><?php } ?>
      <?=$page->header?>
      <?=$page->editorScript?>
    </head>
    <body>
      <h1 cms-title><?=htmlspecialchars($page->title)?></h1>
      <div cms-content-editor="page.content.body"><?=$page->content->body?></div>
      <?=$page->footer?>
    </body>
    </html>
  10. If applicable, add advanced CMS features, such as a Page Template Config, Static Page Components, and onRender functions:
    <!-- 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"><?=$page->content->breadcrumbs?></div>
    
    <!-- onRender / showIf -->
    <?php if($page->properties->showTitle!='N'){ ?><h1 cms-title cms-onRender="showIf(page.properties.showTitle!='N');"><?=htmlspecialchars($page->title)?></h1><?php } ?>
    
    <!-- onRender / addClass -->
    <div cms-onRender="addClass(page.properties.containerClass);" class="<?=htmlspecialchars($page->properties->containerClass)?>"></div>
    
    <!-- onRender / addStyle -->
    <div cms-onRender="addStyle(page.properties.containerStyle);" style="<?=htmlspecialchars($page->properties->containerStyle)?>"></div>
  11. Publish to the Deployment Target, generating a JSON file in the CMS Content subfolder of the PHP application, and test.
Loading
Loading