Search code examples
apostrophe-cms

Add page on backend not admin interface


I want to make an html file that extends layout.html but is not able to be added through the CMS by the user as a type for any other page.


Solution

  • You can solve this problem using parked pages. You can configure certain pages to always exist at certain locations, and the type property is one of those that you can force to a certain value; such parked properties cannot be edited.

    // app.js
    module.exports = {
      modules: {
        'apostrophe-pages': {
          // other configuration, then...
          park: [
            {
              title: 'Special',
              slug: '/special',
              type: 'special',
              published: true,
              parkedId: 'special'
            }
          ]
        }
      }
    }
    

    This is all you need for a top-level page. If you need a parked subpage too, you can add a _children array subproperty to a parked parent.

    Be sure to include a unique parkedId. This prevents any confusion with other parked pages if the configuration changes in other ways.

    Note that you do not have to include special in the types option. Leaving it out is how you can be sure it is never chosen for any other page.

    Parked pages are refreshed at each startup of the app if they have somehow gone missing or changed their parked properties. The interface generally prevents that as well.

    Hope this is helpful!