Search code examples
jekylljekyll-extensions

How do I add a parameter dynamically to jekyll-timeago plugin?


This seems like a really trivial problem, but I can't seem to make it work. I'm trying to add jekyll-timeago plugin to jekyll. In the example docs, it says that if I wanted to add a parameter, I can do this:

{{ page.date | timeago: '2020-1-1' }}

But what if my parameter is a variable? Here is my code:

{% if exp.durationEnd == 'Present'  %} 
   {% assign endDate = site.time %}                        
{% else %}
   {% assign endDate = exp.durationEnd %}
{% endif %}

<div>{{ exp.durationStart }} – {{ exp.durationEnd }} ( {{ exp.durationStart | timeago: '{{ endDate }}' }} ) </div>

I can't seem to make it work. Extra emphasis on:

{{ exp.durationStart | timeago: '{{ endDate }}' }}

The code results in:

2 years and 8 months' }} with that extra ' }} which I think is wrong.

I have tried various expressions like the following but to no avail:

{{ exp.durationStart | timeago: endDate }}

{{ exp.durationStart | timeago: '{% endDate %}' }}

{% assign endDate = timeago exp.durationStart site.time %}


Solution

  • nvm.. I got it.

    {{ exp.durationStart }} – {{ exp.durationEnd }} ( {{ exp.durationStart | timeago : endDate }} )