I was wondering if I could use variables that I create with the createPages API outside the component template.
My scenario is that I create a variable like this:
pages.forEach(page => {
createPage({
path: `${page.slug}`,
component: path.resolve(`src/templates/page-template.js`),
context: {
title: page.title // My Variable
},
})
Now, in my page-template.js file I import a component that holds an external graphql query that is not included in the page-template.js file but I want to use variables in the query.
Can I create variables without the createPages API in Gatsby?