Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

"include" incorrectly treats variables assigned with using some "page.variable" #2043

Closed
notarzvit opened this Issue · 12 comments

5 participants

@notarzvit

In a page:

---
layout: post
title: ...
author: anton
---

In a template:

{% assign author_path = 'authors/~-published-that.html' | replace: '~', page.author %}
{{ author_path }}
{% include {{author_path}} %}

{{ author_path }} outputs the correct path:

authors/anton-published-that.html

But include fails:

Included file '/usr/share/nginx/html/nz-blog/_includes/authors/-published-that.html' not found

As you can see, the anton part is missed in a string when a template is getting included.

@troyswanson

Whoa, this is a really weird. I'm pretty sure this is a problem with Liquid, though, not Jekyll. I found a couple other weird things that are not very explainable that might help the Liquid folks isolate the problem.

Using the code snippet from your template, if the file that {{ author_path }} is pointing to doesn't exist, you a "file not found" error:

Liquid Exception: Included file '/Users/troy/Sites/troyswanson.github.io/_includes/authors/troy-published-that.html' not found in _layouts/post.html

But if the file does exist, you get a "file not found" error for a different file! The tags in the template haven't changed at all:

Liquid Exception: Included file '/Users/troy/Sites/troyswanson.github.io/_includes/authors/-published-that.html' not found in _layouts/post.html

I tried using different characters for the replace token, but they all seem to have the same result.

Another weird thing I found was if you use {% include {{ author_path }} %} (note the spaces within {{ author_path }}), you receive this error:

Liquid Exception: Invalid syntax for include tag: author_path }} Valid syntax: {% include file.ext param='value' param2='value' %} in _layouts/post.html

I took a gander at the liquid repo and found Shopify/liquid#169, which suggested not enclosing the variable in double curly brackets, like so:

{% assign author_path = 'authors/troy-published-that.html' %}
{% include author_path %}

Note that I hard coded the author_path variable as a proof of concept that this method even works. Alas, it did not. I got the following error:

Liquid Exception: Included file '/Users/troy/Sites/troyswanson.github.io/_includes/author_path' not found in _layouts/post.html

Shopify/liquid#134 also talks about this but there isn't really a solution given.

I would open a new issue in the liquid repo and reference this.

@meglio

Hi - thank you for the fast reaction.
I'm not familiar with ruby and it just stopped all my progress with making a blog )
P.S. @notarzvit is our corporate account and it was me who mistakenly used it to report the issue.

@meglio

Btw, even if it is updated / fixed quickly - do you think it will affect Github Pages immediately?

@troyswanson

Yeah, it would all happen pretty quickly I think. The maintainers of this repo and the folks at GitHub are pretty good about deploying bug fixes in short order. That's wholly based on my observation, though. I can't make any promises on their behalf, of course.

@meglio

Any ideas on a workaround so I could move on with this?

@troyswanson

Yeah, maybe this will work...

Use something like this in your post template:

{% include author.html author=page.author %}

This will create an include.author variable inside a snippet called author.html, which you can create a case condition around:

{% case include.author %}
  {% when 'troy' %}
    <!-- troy's bio -->
  {% when 'anton' %}
    <!-- anton's bio -->
{% endcase %}
@mattr-
Owner

Another workaroud that I can think of would be using Jekyll's data feature to do what you're trying to do in the template. Something like this might work:

#assume it's called authors.yaml
anton:
- summary_page: authors/anton-published-that.html

Then you might be able to do something like <a href="{{ site.data.authors["anton"].summary_page }}"> to do what you want.

@meglio

Thanks you very much for both solutions.

It's just that "authors" and "published-that.html" part does repeat.
But anyway it should be okay as it's a workaround only.

@troyswanson

Definitely still create an issue with liquid. This seems like unexpected and buggy behavior.

@meglio

Okay, should I create it?
I though you were going to do it?

@troyswanson

It's your issue, sir. :smile:

@parkr parkr closed this
@parkr
Owner

Added a test case for this in jekyll/cases@ec1a3d4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.