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

Documentation clarification / possible forloop issue? #1

Closed
BrendanBerkley opened this issue Apr 7, 2016 · 6 comments
Closed

Documentation clarification / possible forloop issue? #1

BrendanBerkley opened this issue Apr 7, 2016 · 6 comments

Comments

@BrendanBerkley
Copy link

Hello! Looking to make the move from Jekyll to Hexo but want to keep the templating system, which led me here.

Since I'm new to both your plugin and Hexo, I'm wondering if you could clarify some things in your readme?

  • "To override the liquid-node engine options" - Is this necessary? Why do I need to do this?
  • "...reference the exported Engine property" - If I need to do this, where do I do it?
  • I've been experimenting for a little bit and I correctly guessed that I needed to rename my template files with .liquid extensions.
  • Any tips to get for loops working? Got {{ forloop.length }} to count correctly so I know that it's partially right, but I couldn't get it to output anything other than [object Object].

Anyways, I'm glad this exists. I'm moving to Node for build purposes, but it's nice to have a chance at retaining the familiarity of Liquid. Thanks for your work!

@BrendanBerkley
Copy link
Author

Also having issues with {% include %} tags. Getting an error Unhandled rejection Liquid.FileSystemError: This file system doesn't allow includes.

This issue in liquid-node suggests that it should be possible.

@mattberther
Copy link
Owner

"To override the liquid-node engine options" - Is this necessary? Why do I need to do this?

You would do this if you wanted to do things with the engine directly (like custom filters). The readme shows how you register a custom filter to prepend text. If you're not using a lot of Jekyll filters, you likely won't need this.

"...reference the exported Engine property" - If I need to do this, where do I do it?

If you need to do this, you can choose to put the javascript file in the scripts folder, where hexo will load it during initialization. See https://hexo.io/docs/plugins.html.

Any tips to get for loops working? Got {{ forloop.length }} to count correctly so I know that it's partially right, but I couldn't get it to output anything other than [object Object].

Can you provide more of an example? Some code to demonstrate whats not working?

@mattberther
Copy link
Owner

Also having issues with {% include %} tags. Getting an error Unhandled rejection Liquid.FileSystemError: This file system doesn't allow includes.

This would be an example of where you might reference the exported Engine property.

var Liquid = require("liquid-node");
var renderer = require('hexo-renderer-liquid');
var engine = renderer.Engine;

engine.registerFileSystem(new Liquid.LocalFileSystem("./views"));

@BrendanBerkley
Copy link
Author

Thanks for your patience.

I got a plugin script rolling, got the file system thing working after making some tweaks to your example code. I made a custom filter with your sample code in the readme. Worth noting that adding your sample code doesn't change any functionality; prepend works out of the box.

I guess my confusion in both cases but the filesystem in particular is 'why do I need to configure things to make it work', but now that I'm looking into it, including files might be more of a Jekyll thing than a Liquid thing? If that's true, this makes sense.

Only thing left are those forloops!

I have a YAML file in source/_data/test.yml:

- name: Foo
- name: Bar
- name: Baz

And here's some output that's meant to test various ways of outputting data:

{% for name in site.data.test %}
  <p>
  {{ forloop.length }}
  {{ name }}
  {{ site.data }}
  </p>
{% endfor %}

The output I get is

3 [object Object] [object Object] 
3 [object Object] [object Object] 
3 [object Object] [object Object] 

So, it's getting the data and counting it right, but something is off about how it's being displayed.

I'll poke around liquid_node a bit, see if I need to be adding something to my script.

@BrendanBerkley
Copy link
Author

Worth noting that this works as expected:

{% assign my_array = "foo|bar|baz" | split: "|" %}

<p>{{ my_array }}</p>

{% for item in my_array %}
  <p>{{ item }}</p>
{% endfor %}

So it's something about pulling in external content, be it from the YAML file or pulling in stuff from page.posts.

@mattberther
Copy link
Owner

@BrendanBerkley I suspect that you're getting an object back from site.data.test. Try this code instead:

{% for item in site.data.test %}
  <p>{{ item.name }}</p>
{% endfor %}

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

2 participants