Shopify / Shopify/liquid

Recursion doesn't work by including a file within itself!

Open
#970 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
11.9k
Forks
1.5k
Avg merge
17h 55m
Merged PRs (30d)
3

Description

Hi, I have a file in _includes directory that I'm trying to use like a function by having the file include itself recursively! (which I believe can be done due to this article).

The file _include/courses.html contains:

{% assign orgId = include.lessonID %}

Received ID = {{ orgId }}

{% assign node = include.searchDomain | where:"id",orgId %}
{%- if node.size>0 -%}
  {% comment %}
    If the data was found, then reassing the node from the container array to the right node within the array and proceed.
  {% endcomment %}
  {% assign node = node[0] %}

  <p>CourseID: {{node.id}}</p>
  <p>Name: {{ node.name }}</p>
  <p>Link: {{ node.permalink }}</p>
{%- else -%}
  {%- include courses.html post=post searchDomain=node.content lessonID=lessonID -%}
{%- endif -%}

Now, this is being used by the _layout/courses.html file, containing :

{% include courses.html post=page searchDomain=site.data.courses lessonID=page.lessonInfo.lessonID %}

he file that uses this layout is lister.md:

---
layout: courses
title:  'Test'
lessonInfo:
  lessonID : 1.1
  modName: 'Installing RHEL Server'
  chapterName: 'Using Essential Tools'
---

# There should be some course list around here!

Whenever I try to build the site using bundle exec jekyll serve I get the error:

Liquid Exception: Liquid error (/vm/themeManagement/_includes/courses.html line 16): Nesting too deep included in /_layouts/courses.html
jekyll 3.6.2 | Error: Liquid error (/vm/themeManagement/_includes/courses.html line 16): Nesting too deep included

So, what am I doing wrong and how can I fix it?

The site's _data directory has a file called courses.yaml containing:

- id: 1
  name: 'RHCSA'
  permalink: '/rhcsa'
  description: '<*description>'
  content:
    - id: 1.1
      name: 'Installing RHEL Server'
      permalink: '/rhcsa/installing-rhel-server'
      description: '<*description>'
      content:
        - id: 1.1.1
          name: 'Using Essential Tools'
          permalink: '/rhcsa/installing-rhel-server/using-essential-tools'
          description: '<*description>'
          content:
            - id: 1.1.1.1
              name: 'Man Command'
              permalink: '/rhcsa/installing-rhel-server/using-essential-tools/man-command'
              description: '<*description>'
              content:
            - id: 1.1.1.2
              name: 'Understanding Globbing and Wildcards'
              permalink: '/rhcsa/installing-rhel-server/using-essential-tools/understanding-globbing-and-wildcards'
              description: '<*description>'
              content:

          (...and so on...)

NOTE Through extensive testing I've confirmed that the error is generated solely due to using searchDomain=node.content in _include/courses.html.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the recursive include at line 16 of _include/courses.html and reproduce the failure using bundle exec jekyll serve. Trace how the include receives searchDomain=node.content and reaches Liquid's nesting limit. Done should identify whether this recursion is supported and document or test the resulting behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.