Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Templates not working on fresh Spike install #91

Open
craigmdennis opened this issue Apr 7, 2018 · 3 comments
Open

Templates not working on fresh Spike install #91

craigmdennis opened this issue Apr 7, 2018 · 3 comments

Comments

@craigmdennis
Copy link

craigmdennis commented Apr 7, 2018

Spike version: 2.2.1
Node version: 9.11.1 using NVM (have also tried 9.3.0

Demo: https://github.com/craigmdennis/example-spike-contentful

  1. spike new example.com
? What is the name of your project? example
? Describe your project Example
? What is your github username? craigmdennis
? Would you like to use whitespace-sensitive syntax? No
? Would you like a production config file? No
  1. spike compile
  2. npm i spike-contentful -S
  3. Add configuration from the README using the demo Contentful app
const htmlStandards = require('reshape-standard')
const cssStandards = require('spike-css-standards')
const jsStandards = require('spike-js-standards')
const pageId = require('spike-page-id')
const env = process.env.SPIKE_ENV
const Contentful = require('spike-contentful')
const locals = {}

module.exports = {
  plugins: [
    new Contentful({
      addDataTo: locals,
      accessToken: '1e1dd64d5385d015b2e8f622f622b67c4147a812d7ab3f8146e583416009f31b',
      spaceId: 'noiekra805sy',
      contentTypes: [
        {
          name: 'posts',
          id: '2wKn6yEnZewu2SCCkus4as',
          template: {
            path: 'templates/post.html',
            output: post => {
              return `posts/${post.id}.html`
            }
          }
        }
      ]
    })
  ],
  devtool: 'source-map',
  ignore: ['**/layout.html', '**/_*', '**/.*', 'readme.md', 'yarn.lock', 'package-lock.json'],
  reshape: htmlStandards({
    locals: () => locals,
    minify: env === 'production'
  }),
  postcss: cssStandards({
    minify: env === 'production',
    warnForDuplicates: env !== 'production'
  }),
  babel: jsStandards()
}
  1. spike compile

Instead of rendering post pages, Spike outputs a single templates/post.html file, as if it were a normal page.

  1. When trying to use {{ item.title }} required in the README, there is an undefined error for item:
{ ModuleBuildError: Module build failed: TypeError: Cannot read property 'title' of undefined
    at eval (eval at module.exports (/Users/craigmdennis/Sites/example.com/node_modules/reshape-code-gen/lib/scoped_eval.js:9:10), <anonymous>:1:156)
    at eval (eval at module.exports (/Users/craigmdennis/Sites/example.com/node_modules/reshape-code-gen/lib/scoped_eval.js:9:10), <anonymous>:1:170)
    at evalNode (/Users/craigmdennis/Sites/example.com/node_modules/reshape-eval-code/lib/index.js:27:70)
    at util.modifyNodes (/Users/craigmdennis/Sites/example.com/node_modules/reshape-eval-code/lib/index.js:21:40)
    at when.resolve.then (/Users/craigmdennis/Sites/example.com/node_modules/reshape-plugin-util/lib/index.js:26:29)
    at tryCatchReject (/Users/craigmdennis/Sites/example.com/node_modules/when/lib/makePromise.js:845:30)
    at runContinuation1 (/Users/craigmdennis/Sites/example.com/node_modules/when/lib/makePromise.js:804:4)
    at Fulfilled.when (/Users/craigmdennis/Sites/example.com/node_modules/when/lib/makePromise.js:592:4)
    at ContinuationTask.run (/Users/craigmdennis/Sites/example.com/node_modules/when/lib/makePromise.js:702:24)
    at Scheduler._drain (/Users/craigmdennis/Sites/example.com/node_modules/when/lib/Scheduler.js:62:19)
    at runLoaders (/Users/craigmdennis/Sites/example.com/node_modules/webpack/lib/NormalModule.js:195:19)
    at /Users/craigmdennis/Sites/example.com/node_modules/loader-runner/lib/LoaderRunner.js:364:11
    at /Users/craigmdennis/Sites/example.com/node_modules/loader-runner/lib/LoaderRunner.js:230:18
    at context.callback (/Users/craigmdennis/Sites/example.com/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
    at tryCatchReject (/Users/craigmdennis/Sites/example.com/node_modules/when/lib/makePromise.js:845:30)
    at runContinuation1 (/Users/craigmdennis/Sites/example.com/node_modules/when/lib/makePromise.js:804:4)
    at Rejected.when (/Users/craigmdennis/Sites/example.com/node_modules/when/lib/makePromise.js:625:4)
    at Pending.run (/Users/craigmdennis/Sites/example.com/node_modules/when/lib/makePromise.js:483:13)
    at Scheduler._drain (/Users/craigmdennis/Sites/example.com/node_modules/when/lib/Scheduler.js:62:19)
    at Scheduler.drain (/Users/craigmdennis/Sites/example.com/node_modules/when/lib/Scheduler.js:27:9) id: '6647cf5f' }

This is the contents of the post.html template:

<extends src='../layout.html'>
  <block name='content'>
    <h1>{{ item.title }}</h1>
  </block>
</extends>

JSON.stringify(post) also causes a Module build failed: TypeError: Converting circular structure to JSON with the default Contentful 'Blog' app. When simply referencing parts of the JSON it works fine:

<ul>
  <each loop="post of contentful.posts">
    <li>{{ post.fields.title }}</li>
  </each>
</ul>

so getting data from Contentful is not the issue.

Let me know if I'm doing something obviously wrong. If so, I can submit a PR to update the README to clarify. Otherwise, suggestions?

@jescalan
Copy link
Member

Hey I'm really sorry for the late response here, but making the template an ignored file should do the trick here - easiest way would be to prefix it with an underscore.

@craigmdennis
Copy link
Author

craigmdennis commented May 29, 2018

making the template an ignored file should do the trick here - easiest way would be to prefix it with an underscore.

This results in no file being output at all.
Updated my repo with your suggestion: https://github.com/craigmdennis/example-spike-contentful

@IohannesArnold
Copy link

So I had this problem and then fiddled around with things until I didn't, and I never managed to quite diagnose what exactly was going wrong. But I think it has to do with Spike attempting to render the Contentful template as a static view without the supplemented Contentful object, and therefore failing. What ended up working for me was putting layout.html in templates together with post.html, so my post.html began simply:

<extends src='layout.html'>

while my index.html begins:

<extends src='../templates/layout.html'>

Anyway, don't know if this is too late to be helpful, but just thought I'd add.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants