レイアウトを分割する目的で、日付を変数に割り当てようとしています。おそらくこれを行うためのより良い方法があるので、代替案をお勧めします。
news_date という日付フィールドを持つ、news_items のモデルがあります。モデル エントリのそれぞれを調べて、新しい年に遭遇するたびに新しいセクションを開始したいと考えています。私の計画はかなり基本的でした:
{% assign curYear = "" %}
{% for news in contents.news_items %}
{% assign prevYear = curYear %}
{% assign curYear = news.news_date.year %} <-- this does not work
{% if prevYear != curYear %}
<h1>Press Releases for {{ news.news_date | format_date: '%Y' }}</h1>
{% endif %}
<p>{{curYear}}</p> <-- this is always empty
<p>{{news.content}}</p>
{% endfor %}
のように、他のさまざまな構文を試しTime.parseTime(news.news_date).year
ましたが、Liquid では任意の Ruby を実行できないようです。ここで私が望むものを達成する方法はありますか?
ご協力ありがとうございます。