title: Adding a 2nd dynamic template to Gatsby/NetlifyCMS correctly - Where am I going wrong?
body: <p>I've added a blog page that I integrated with NetlifyCMS and it works wonderful. However, I need to have one more dynamic page on my site that displays services and each service will have its own generated template, will pretty much be very similar to the blog page in theory.</p>
  <p>So I read around a bunch of different solutions but kept hitting a wall. What am I doing wrong here? and whats the simplest way to make this work, as I wont be adding any other dynamic pages moving forward.</p>
  <p>Here was my gatsby-node.js when I just had the blog page and everything worked great:</p>
  <pre><code>const { createFilePath } = require(&quot;gatsby-source-filesystem&quot;)
  exports.onCreateNode = ({ node, actions, getNode }) =&gt; {
    const { createNodeField } = actions
    if (node.internal.type === `MarkdownRemark`) {
      const value = createFilePath({ node, getNode })
      createNodeField({
        name: `slug`,
        node,
        value,
      })
    }
  }
  
  //Blog
  async function getPageData(graphql) {
    return await graphql(`
      {
        blogPosts: allMarkdownRemark {
          edges {
            node {
              fields {
                slug
              }
            }
          }
        }
      }
    `)
  }
  
  const path = require(`path`)
  exports.createPages = async ({ graphql, actions }) =&gt; {
    const { data } = await getPageData(graphql)
    data.blogPosts.edges.forEach(({ node }) =&gt; {
      const { slug } = node.fields
      actions.createPage({
        path: `/articles${slug}`,
        component: path.resolve(&quot;./src/templates/articlepost.js&quot;),
        context: {slug: slug },
      })
    })
  }
  </code></pre>
  <p>So I took a stab it and tried to do the same thing but adding my services page. Here is what that ended up looking like:</p>
  <p>gatsby-node.js</p>
  <pre><code>const { createFilePath } = require(&quot;gatsby-source-filesystem&quot;)
  exports.onCreateNode = ({ node, actions, getNode }) =&gt; {
    const { createNodeField } = actions
    if (node.internal.type === `MarkdownRemark`) {
      const value = createFilePath({ node, getNode })
      createNodeField({
        name: `slug`,
        node,
        value,
      })
    }
  }
  
  async function getBlogData(graphql) {
    return await graphql(`
      {
        blogPosts: allMarkdownRemark(
          filter: { frontmatter: { template: { eq: &quot;articlepost&quot; } } }
        ) {
          edges {
            node {
              fields {
                slug
              }
            }
          }
        }
      }
    `)
  }
  
  async function getServiceData(graphql) {
    return await graphql(`
      {
        servicePosts: allMarkdownRemark(
          filter: { frontmatter: { template: { eq: &quot;service&quot; } } }
        ) {
          edges {
            node {
              fields {
                slug
              }
            }
          }
        }
      }
    `)
  }
  
  const path = require(`path`)
  exports.createPages = async ({ graphql, actions }) =&gt; {
    const blogPage = path.resolve(&quot;./src/templates/articlepost.js&quot;)
    const servicePage = path.resolve(&quot;./src/templates/service.js&quot;)
  
    const { data } = await getBlogData(graphql)
    data.blogPosts.edges.forEach(({ node }) =&gt; {
      const { slug } = node.fields
      actions.createPage({
        path: `/articles${slug}`,
        component: blogPage,
        context: { slug: slug },
      })
    })
  
    const { serviceData } = await getServiceData(graphql)
    serviceData.servicePosts.edges.forEach(({ node }) =&gt; {
      const { slug } = node.fields
      actions.createPage({
        path: `/streaming-services${slug}`,
        component: servicePage,
        context: { slug: slug },
      })
    })
  }
  </code></pre>
  <p>My blog page still works fine but I get error:</p>
  <p><a href="https://i.stack.imgur.com/tpOQq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tpOQq.png" alt="console error" /></a></p>
  <p>As you can see I added a template type to my config.yml, that now shows in my frontmatter to separate my posts, but I think it may have just confused me a little more. Totally fine with removing the template types from frontmatter, but really need a very simple way for this to work.</p>
  <p>Many thanks in advance!</p>