Skip to content

How to generate dynamic pages from other pages and shared data? #423

Closed Answered by oscarotero
boeckMt asked this question in Q&A
Discussion options

You must be logged in to vote

The pages generated dynamically don't inherit the contextual data.
You need to include the desired data in the yielded object. For example:

export default function* (data) {
    const { search, config } = data;

    const compareProducts = search.pages("type=product");

    // Create pages to compare the products
    for (const page1 of compareProducts) {
        for (const page2 of compareProducts) {
            if (page1 !== page2) {
              yield {
                 title: `Comparing ${page1.data.title} vs ${page2.data.title}`,
                 layout: "compare-page.njk",
                 page1,
                 page2,
                 config,
              }
            }
        }

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@boeckMt
Comment options

@oscarotero
Comment options

Answer selected by boeckMt
@boeckMt
Comment options

@oscarotero
Comment options

@boeckMt
Comment options

@oscarotero
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants