Search code examples
apostrophe-cms

What is the URL structure of pieces content?


I am adding a custom piece type as follows:

module.exports = {
  extend: "apostrophe-pieces",
  name: "product",
  label: "Product",
  pluralLabel: "Products",
}

added to app.js as follows:

products: {}

directory structure:

- products/
    index.js (contains module.exports from above)

Add a product successfully, try to visit a url that seems like it ought to exist (/products/, /product/, /), and none of them work.

Am I overlooking some critical piece that enables the custom piece to be rendered from a URL?


Solution

  • Extending apostrophe-pieces creates a new content type on the back end. Now, to bring it into the website's front end, you will want to extend apostrophe-pieces-pages, which creates a page type that can be used to display a list view of pieces, with pagination, and click through to permalink "pages" for each one.

    You can write your own index.html and show.html templates, respectively. You should complete the reusable content with pieces tutorial to learn more about this.

    The URL of each individual piece is then:

    /page-url/piece-slug

    If you have more than one pieces-page of the appropriate type in your page tree, then the best parent page URL to use is generated dynamically based on the tags of the piece and the tags set under "with these tags" in the page settings of the page. It is possible to override this mechanism to use other criteria.

    You can also pull pieces onto pages here and there around the site using apostrophe-pieces-widgets. Extending this module gives you a way to pop pieces into pages here and there via an editable widget that can be anywhere on the site. But, you'll still want apostrophe-pieces-pages to provide SEO-friendly discoverability and permalinks for every individual piece.

    You can find examples of apostrophe-pieces-pages in a working project in the apostrophe-samples project.