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

`{% %}` results in "Template render error." #1777

Closed
liuzc opened this Issue Feb 25, 2016 · 10 comments

Comments

3 participants
@liuzc
Copy link

liuzc commented Feb 25, 2016

When I disable highlight in _config.yml. A template render error occurred. But I want to use use google prettify highlight code, So I must need disable highlight.

highlight:
  enable: false
  line_number: false
  auto_detect: false
  tab_replace:
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
Template render error: Error: Unable to call `is_post`, which is undefined or falsey
    at Object.callWrap (/Users/LiuZhichao/Blog/node_modules/nunjucks/src/runtime.js:223:15)
    at root [as rootRenderFunc] (eval at <anonymous> (/Users/LiuZhichao/Blog/node_modules/nunjucks/src/environment.js:450:24), <anonymous>:8:38)
    at null.<anonymous> (/Users/LiuZhichao/Blog/node_modules/nunjucks/src/environment.js:387:18)
    at Object.exports.withPrettyErrors (/Users/LiuZhichao/Blog/node_modules/nunjucks/src/lib.js:24:16)
    at Obj.extend.render (/Users/LiuZhichao/Blog/node_modules/nunjucks/src/environment.js:374:20)
    at Obj.extend.renderString (/Users/LiuZhichao/Blog/node_modules/nunjucks/src/environment.js:261:21)
    at /Users/LiuZhichao/Blog/node_modules/hexo/lib/extend/tag.js:56:9
    at tryCatcher (/Users/LiuZhichao/Blog/node_modules/bluebird/js/main/util.js:26:23)
    at Promise._resolveFromResolver (/Users/LiuZhichao/Blog/node_modules/bluebird/js/main/promise.js:480:31)
    at new Promise (/Users/LiuZhichao/Blog/node_modules/bluebird/js/main/promise.js:70:37)
    at Tag.render (/Users/LiuZhichao/Blog/node_modules/hexo/lib/extend/tag.js:55:10)
    at Object.tagFilter [as onRenderEnd] (/Users/LiuZhichao/Blog/node_modules/hexo/lib/hexo/post.js:253:16)
    at /Users/LiuZhichao/Blog/node_modules/hexo/lib/hexo/render.js:55:19
    at tryCatcher (/Users/LiuZhichao/Blog/node_modules/bluebird/js/main/util.js:26:23)
    at Promise._settlePromiseFromHandler (/Users/LiuZhichao/Blog/node_modules/bluebird/js/main/promise.js:507:31)
    at Promise._settlePromiseAt (/Users/LiuZhichao/Blog/node_modules/bluebird/js/main/promise.js:581:18)
    at Promise._settlePromises (/Users/LiuZhichao/Blog/node_modules/bluebird/js/main/promise.js:697:14)
    at Async._drainQueue (/Users/LiuZhichao/Blog/node_modules/bluebird/js/main/async.js:123:16)
    at Async._drainQueues (/Users/LiuZhichao/Blog/node_modules/bluebird/js/main/async.js:133:10)
    at Immediate.Async.drainQueues [as _onImmediate] (/Users/LiuZhichao/Blog/node_modules/bluebird/js/main/async.js:15:14)
    at processImmediate [as _immediateCallback] (timers.js:383:17)
@Xuanwo

This comment has been minimized.

Copy link
Contributor

Xuanwo commented Feb 25, 2016

I'll build a environment for this issue, wait for a moment.

@Xuanwo Xuanwo added the need-verify label Feb 25, 2016

@liuzc

This comment has been minimized.

Copy link

liuzc commented Feb 25, 2016

I can disable this option before.But today I init a new blog,when I change highlight enable value to false, the error occurred. It may not be compatible with a plug-in or module? I'm not sure.

My plug-in list:

  "dependencies": {
    "hexo": "^3.1.0",
    "hexo-autonofollow": "0.0.1",
    "hexo-clean-css": "0.0.2",
    "hexo-deployer-git": "0.0.4",
    "hexo-generator-archive": "^0.1.2",
    "hexo-generator-baidu-sitemap": "^0.1.2",
    "hexo-generator-category": "^0.1.2",
    "hexo-generator-feed": "^1.0.3",
    "hexo-generator-index": "^0.1.2",
    "hexo-generator-sitemap": "^1.0.1",
    "hexo-generator-tag": "^0.1.1",
    "hexo-html-minifier": "0.0.1",
    "hexo-renderer-ejs": "^0.1.0",
    "hexo-renderer-marked": "^0.2.4",
    "hexo-renderer-stylus": "^0.3.0",
    "hexo-server": "^0.1.2",
    "hexo-uglify": "0.0.3"
  }

$hexo -v:

hexo: 3.1.1
os: Darwin 15.3.0 darwin x64
http_parser: 2.6.2
node: 5.7.0
v8: 4.6.85.31
uv: 1.8.0
zlib: 1.2.8
ares: 1.10.1-DEV
icu: 56.1
modules: 47
openssl: 1.0.2f
@Xuanwo

This comment has been minimized.

Copy link
Contributor

Xuanwo commented Feb 25, 2016

It looks OK: https://xuanwo.org/hexo-issue-test/2016/02/25/1777/
And you can see config here: https://github.com/Xuanwo/hexo-issue-test/blob/master/_config.yml#L40-L44

Hexo version:

hexo: 3.1.1
os: Linux 4.2.0-27-generic linux x64
http_parser: 2.6.2
node: 5.7.0
v8: 4.6.85.31
uv: 1.8.0
zlib: 1.2.8
ares: 1.10.1-DEV
icu: 56.1
modules: 47
openssl: 1.0.2f

Package:

  "name": "hexo-site",
  "version": "0.0.0",
  "private": true,
  "hexo": {
    "version": "3.1.1"
  },
  "dependencies": {
    "hexo": "^3.1.1",
    "hexo-deployer-git": "^0.1.0",
    "hexo-generator-archive": "^0.1.4",
    "hexo-generator-category": "^0.1.3",
    "hexo-generator-index": "^0.2.0",
    "hexo-generator-tag": "^0.2.0",
    "hexo-renderer-ejs": "^0.1.1",
    "hexo-renderer-marked": "^0.2.9",
    "hexo-renderer-stylus": "^0.3.0",
    "hexo-server": "^0.1.3"
  }
}
@liuzc

This comment has been minimized.

Copy link

liuzc commented Feb 25, 2016

Could you please use this theme https://github.com/liuzc/hexo-theme-read test again. Thx.

@Xuanwo

This comment has been minimized.

Copy link
Contributor

Xuanwo commented Feb 25, 2016

The theme works well on my environment.
I have noticed that my hexo-renderer-marked is newer than you , may be you can update your dep to have a try.

you can see the page here : https://xuanwo.org/hexo-issue-test/2016/02/25/1777/

@liuzc

This comment has been minimized.

Copy link

liuzc commented Feb 25, 2016

Thank you very much. I will test it again.
You can close this issues now. Thank you again.

@Xuanwo

This comment has been minimized.

Copy link
Contributor

Xuanwo commented Feb 25, 2016

Issue will be closed when sloved, so don't care about this. If closed too early, I will forget about this issue, 😆

Xuanwo added a commit to Xuanwo/hexo-issue-test that referenced this issue Feb 25, 2016

@liuzc

This comment has been minimized.

Copy link

liuzc commented Feb 25, 2016

I find the cause of this problem.just because the following fields included in my article:

     {% if is_post() %}
     {% include '../_partials/reward.swig' %}
     {% endif %}

you can create a new post, then copy this content to your post. then type hexo s in your console,you will see this error.

@Xuanwo

This comment has been minimized.

Copy link
Contributor

Xuanwo commented Feb 25, 2016

Well, I got it. We can't use {% and %} in article content because nunjucks will treat them as template.
You can try to use {% raw %} and {% endraw %} to include them or use escape.

@leesei

This comment has been minimized.

Copy link
Member

leesei commented Mar 1, 2016

Put content in backticks, codeblock or raw tags to bypass Nunjucks parsing issue.
https://hexo.io/docs/troubleshooting.html#Escape_Contents
See #1510 for discussion of disabling Nunjucks.

@leesei leesei closed this Mar 1, 2016

@leesei leesei changed the title Disable highlight results in "Template render error." `{% %}` results in "Template render error." Mar 1, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment