Skip to content

gakimball/gatsby-plugin-global-context

Repository files navigation

gatsby-plugin-global-context

Gatsby plugin to apply context to every page

Travis npm

This plugin adds context values to every page in your Gatsby project. Use this if you want to add a "global variable" that any page can use in its GraphQL query.

Installation

npm install gatsby-plugin-global-context

Usage

Add the plugin to gatsby-config.js:

module.exports = {
  plugins: [
    {
      resolve: 'gatsby-plugin-global-context',
      options: {
        context: {
          kittens: true
        }
      }
    }
  ]
};

Now, any page will have access to the values defined in context above. This includes pages in your pages/ folder, and pages created with Gatsby's createPage().

import React from 'react';
import { graphql } from 'gatsby';

export default () => <h1>Hi, I am a page</h1>;

export const query = graphql`
  query PageQuery($kittens: Boolean!) {
    # ...
  }
`;

Options

The only option is context, which should be an object of context values to add to every page.

Local Development

git clone https://github.com/gakimball/gatsby-plugin-global-context
cd gatsby-plugin-global-context
npm install
npm test

License

MIT © Geoff Kimball

About

Gatsby plugin to apply context to every page

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published