wildlyinaccurate / jekyll-responsive-image

An unopinionated Jekyll plugin for generating and using responsive images
MIT License
332 stars 48 forks source link

Liquid filters (specifically `absolute_url`) break build if used in the responsive image template #78

Closed jerturowetz closed 5 years ago

jerturowetz commented 5 years ago

If I try to use liquid filters in the responsive image template file I get the following error:

Liquid Exception: undefined method `config' for nil:NilClass in /_layouts/default.html

Example template file

The following are the contents of my template file. When I remove the | absolute_url filter everything works fine.

{% assign largest = resized | sort: 'width' | last %}
{% capture srcset %}
{% for i in resized %}
    /{{ i.path }} {{ i.width }}w,
{% endfor %}
    /{{ path }} {{ original.width }}w
{% endcapture %}

<img src="{{ path | absolute_url }}" alt="{{ alt }}" class="{{ class }}" srcset="{{ srcset | strip_newlines }}" sizes="{{ sizes }}" />

System information

Expectations

Expected behaviour: Liquid filters accessible Actual behaviour: No worky

wildlyinaccurate commented 5 years ago

Hmm, this might be a tricky one. I don't have time to look into a proper fix right now, but I think you should be able to get around it by doing something like this instead:

{% assign url = path | absolute_url %}
<img src="{{ url }}">
jerturowetz commented 5 years ago

I did not yet try that one, lemme give it a go and advise.

iangreenleaf commented 5 years ago

The suggested workaround did not work for me, but I was able to get a (fragile) solution with:

<img src="{{ site.url }}/{{ path }}" />
stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

iangreenleaf commented 5 years ago

Would still love to see this fixed.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.