I created a custom generator in Jekyll that randomly select templates and applies posts to them. To organize, I created a Section class that organizes each section and adds it to an array in site data called homepage_sections. This works as expected, but when I try and reference anything in the Section object stored in *site.data[“homepage_sections”], I get an error. The Section object holds a Hash of placements, each having a template and set of Jekyll posts.
template (index.html) – one example of what I have tried
{% for section in site.data["homepage_sections"] %}
<section class="section">
<div class="container-fuild">
<div class="masonry-box clearfix">
{% for placement in section.placements %}
<div class="{{ placement[0] }}-side">
{% include posts/{{placement[1].template}}.html %}
</div>
{% endfor %}
</div>
</div>
</section>
{% endfor %}
From what I understand, you’re trying to access an instance variable (“@” variable) from your liquid template, when the syntax you used (instance.property) causes liquid to try calling the to_liquid method on your Section object.
Thank you @pcouy. I will look into that. I will say that the instance variable I am trying to access is a Hash, so I would have hoped it would have just worked
The instance varieble being a hash or something else does not seem related to your error. It’s that doing instance.property in a template seems to call the instance.to_liquid method. From what I understand, to_liquid is expected to return a Hash of the properties you want to be able to access from templates. Using the Convertible mixin seems to be the Jekyll way to do that
@pcouy Going down the Convertible mixin route is proving to be a rabbit hole of needing other Jekyll-based objects (e.g. Converter) when the variable I have in the loop
{% for placement in section.placements %}
is a Hash. I am not sure why Jekyll/Liquid thinks it isn’t