inukshuk / jekyll-scholar

jekyll extensions for the blogging scholar
MIT License
1.12k stars 102 forks source link

Conditional by citation count #310

Open kaba2 opened 4 years ago

kaba2 commented 4 years ago

How can I use bibliography_count inside conditionals? The following Jekyll code fails by "Unknown operator bibliography_count":

{% if {% bibliography_count --cited %} > 0 %}

<h2>References</h2>

{%- bibliography --cited -%}
{% endif %}
kaba2 commented 4 years ago

Here is a workaround. Is it supposed to work like this?

{%- capture citecount -%}
{%- bibliography_count --cited -%}
{%- endcapture -%}

{% if {{citecount}} != "0"  %}

<h2>References</h2>

{%- bibliography --cited -%}
{% endif %}
AlasdairGray commented 2 years ago

This was just what I was looking for. It would be great to add these instructions to the README.

norseghost commented 3 months ago

the above didn't work for me. this was my workaround:

{% comment %}
Capture cites so i can check for a populated list later
{% endcomment %}
{% capture cites %}
{% bibliography --cited_in_order %}
{% endcapture %}
{% comment %}
The bibliography tag returns an empty list if there are no citations
(nil would seem to make more sense, but hey)
Thus, check for a list element in the returned bibliography to indicate
I actually cited something in this article.
{% endcomment %}
{% if cites contains "<li" %} <section class="footnotes reference">
    <h1 id="">References</h1>
    {{cites | markdownify }}
    </section>
    {% endif %}