Jekyll treating custom variable in included file as filename

Viewed 31

I've got a custom variable that I'm passing into my include file which is strangely being treated as the filename. I'm not sure what I'm doing wrong:

I'm including my component with:

{% include_relative includes/form/components/modal.html for="purpose" %}

And the contents of the includes/form/components/modal.html is:

<div class="modal-custom modal-custom-white" data-modal-custom="{% include.for %}" data-modal-requires-update-button>
  <div class="modal-custom-background bg-white"></div>
  <div class="modal-custom-content p-3">

    {% if include.title %}
      <h5 class="font-weight-normal text-dark mb-3">{% include.title %}</h5>
    {% else %}
      <h5 class="font-weight-normal text-dark mb-3"><strong>Tap</strong> to choose:</h5>
    {% endif %}

    <!-- Modal content here -->
    {% if include.content %}
      {% include.content %}
    {% endif %}

  </div>
  <button type="button" class="modal-custom-close is-large bg-light" onclick="toggleModal('purpose', 'close-retain');diposeExpandedToggler('purpose', true)"></button>
</div>

I'm running the latest version of Jekyll, version 4.2.0 and if I remove the for then everything works just fine. I've tried:

  • renaming the variable
  • cleaning the cache
  • formatting the variable in different ways such as: for=purpose and for="purpose"

I've created something similar in another component and everything works fine there, but the error I'm getting here is:

Liquid Exception: Could not locate the included file '.for' in any of ["/Users/USER/Sites/MY-PROJECT/src/_includes"]. Ensure it exists in one of those directories and, if it is a symlink, does not point outside your site source. in icicle.html

Which is strange. What am I missing?

1 Answers

You probably just need to use the output tags {{ include.for }} rather than the non-output ones {% include.for %}. This is the case for include.title and include.content here as well.

You should pass a variable without the quotes, otherwise you'll be passing the string literal "purpose" instead of the value that the purpose variable holds.

Although it might work anyway, I'd avoid using for as a key if possible since it's the for loop keyword used in Liquid.

Related