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

Detect misusage of handlebars #85

Open
1 of 2 tasks
kirrg001 opened this issue Sep 11, 2017 · 2 comments
Open
1 of 2 tasks

Detect misusage of handlebars #85

kirrg001 opened this issue Sep 11, 2017 · 2 comments

Comments

@kirrg001
Copy link
Contributor

kirrg001 commented Sep 11, 2017

Steps to reproduce:

  1. Add e.g. {{#if img_url feature_image}} in your post.hbs
  2. Navigate to any post
TypeError: [post.hbs] Cannot read property 'includeZero' of undefined
    at Object.<anonymous> (/ghost/node_modules/express-hbs/node_modules/handlebars/dist/cjs/handlebars/helpers/if.js:16:22)

The if helper is an inbuilt helper of Handlebars. People sometimes misuse this helper.
Would be great to detect that in gscan.

  • add a warning in our instructions and double check docs
  • add detection in gscan
@ErisDS
Copy link
Member

ErisDS commented Sep 11, 2017

As far as I know, the only reason we're seeing this happen is because the output from gscan about changing instances of image tell them to do a straight swap to img_url feature_image.

I've never seen people do this before 1.0 - and all of them were following instructions from gscan.

Therefore, before we add an extra check, I think the first task is to fix the instructions?

@kirrg001 kirrg001 changed the title Detect misusage of handlebars if helper Detect misusage of handlebars Nov 28, 2017
@kirrg001
Copy link
Contributor Author

kirrg001 commented Nov 28, 2017

As far as I know, the only reason we're seeing this happen is because the output from gscan about changing instances of image tell them to do a straight swap to img_url feature_image.

100%.

I'll added subtasks to the issue.


Another case is if you are using the {{pagination}} helper wrong.
e.g. if the helper is not used within a post context object. Then Ghost would complain and throw pagination data is not an object or is a function error. This error message should be improved. Docs should be improved as well.

kirrg001 added a commit that referenced this issue Nov 28, 2017
refs #85

- reduce chance that people will misusage handlebars
  - {{if img_url feature_image}}
kirrg001 added a commit to kirrg001/Ghost that referenced this issue Nov 28, 2017
refs https://github.com/TryGhost/Team/issues/41, refs TryGhost/gscan#85

- if you are using the pagination helper not inside a resource context, you will receive an error
- improve error message, because it was not clear what happened
- downgrade error level to normal, because it's not a critical error from Ghost's perspective, from user perspective it is
- added help docs link and added a callout to our docs
kevinansfield pushed a commit to TryGhost/Ghost that referenced this issue Nov 28, 2017
refs TryGhost/Product#41, refs TryGhost/gscan#85

- if you are using the pagination helper not inside a resource context, you will receive an error
- improve error message, because it was not clear what happened
- downgrade error level to normal, because it's not a critical error from Ghost's perspective, from user perspective it is
- added help docs link and added a callout to our docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants