You are looking at the old Apostrophe 0.5 documentation. It is deprecated for new projects. Check out the latest version!

Custom Page Properties

← Previous: Fancy pages

Let's say we already have a page type called "Company," set up with the rest of our page types in app.js:

  pages: [
    'home',
    'default',
    'company'
  ]

This is fine but we want to know the year each company was incorporated.

So let's subclass apostrophe-fancy-page:

modules: {
  // Other modules go here
  company: {
    extend: 'apostrophe-fancy-page',
    name: 'company',
    label: 'Company',
    addFields: [
      {
        name: 'incorporated',
        label: 'Incorporated',
        type: 'integer'
      }
    ]
  }
}

We also must create the folder lib/modules/company in our project. This folder can start out empty and often stays that way.

Now restart your site and add a page with the "Company" page type. Boom! There's an "Incorporated" field in "Page Settings."

You can access this field in your company.html page template:

{{ page.typeSettings.incorporated }}

"OK, but what other field types are there?" apostrophe-fancy-page uses Apostrophe schemas. You can do anything that is supported by Apostrophe schemas. It's exactly like adding fields to snippet subclasses like apostrophe-blog and apostrophe-events.

Passing Extra Information to Templates

You can pass extra information to the page template by adding properties to the req.extras object. Any properties of that object are automatically visible to Nunjucks when the page is rendered. They appear as top-level variables, so req.extras.myThing becomes myThing in the template.

Adding Joins

You can add joins too. They work exactly as documented here. You can join with other fancy page types, or with snippet instance types like blogPost.

Next: Restricting child page types →