2017-02-23 1 views
0

更新日: イベントと呼ばれるコレクションがあります。このコレクションの各アイテムには、日付の時刻形式(例:2017-02-23 00:05:09 +0700)として入力されるカスタムメタ「開始時刻と日付:」があります。私の家のレイアウトでは、「開始時刻と日付:」が今日の日付と一致するイベントのみが表示されます。今日の日付と一致しますが、システム(ないホーム画面上でレンダリングされたリスト内)のそれらの順序がデフォルトpage.dateなくイベントによってソートされたイベントのリストになり配列内の次/前の項目を、カスタムのフロントマットでソートする場合は、今日の日付と一致する場合のみ取得します。

{% assign events = site.events | sort: 'Start time and date' %} 
{% for event in events %} 
    {% assign today = site.time | date: "%b %d" %} 
    {% assign eventdate = event['Start time and date'] | date: "%b %d" %} 
    {% if eventdate == today %} 
    ... 
    {% else %} 
    {% endif %} 
{% endfor %} 

[ 'スタート時間と日付]]。私がイベントページ内に位置し、page.nextを呼び出すと、今日のイベントの私の生成されたリストの次のイベントではなく、次のイベントページであるpage.next (私は彼らが日付でソートされていると仮定します)。

どのように私のカスタムメタイベント['開始時刻と日付]]を使用して、現在のイベントからの相対的な次のイベントと前のイベントにアクセスできますか?基本的に今日の日付でネットまたは前のイベントを取得します。

助けてください、私はこの1つで私のジキル知識を使い果たしました。

+0

メタ値にスペースを入れることはできません。それはあなたにそれを使用する際に液体構文エラーを与えるでしょう。 –

+0

あなたはそれを{{post ['スペースのあるメタ名]}}として呼び出す必要があります。 – ntnlbd

答えて

0

だから私はこの方法で解決することができた長い闘いの後、おそらく誰かが=を、それを整理するために、このの編集を行うことができる場合)ので、私は感謝される

これを行うには、簡単かつクリーンな方法があります
{% assign today = site.time | date: "%d" %} // find current date 
{% assign allevents = site.events | sort: 'Start time and date' %} // sort all items in collections event by custom metafield similar to the standard date field 

{% for event in allevents %} // loop through all events 
{% assign eventdate = event['Start time and date'] | date: "%d" %} // assign event date from the custom meta in the event item 
{% if eventdate == today %} // check if event date equals today 
    {% if event.url == page.url %} // check if event url is also currently generated page url 

     {% assign preveventindex = forloop.index | plus: 1 %} // find the index of previous event in the array 
     {% assign nexteventindex = forloop.index | minus: 1 %} // find the index of next event in the array 

     {% for event in allevents %} // loop throug events again 
     {% assign today = site.time | date: "%d" %} // set current date again 
     {% assign eventdate = event['Start time and date'] | date: "%d" %} // set event date again 

     {% if eventdate == today %} // check if event generated has current date 
      {% if forloop.index == nexteventindex %} // check if next event index is correct 

      {{ forloop.index }} - 
      {{ event.url }} 
      {% assign nexteventurl = event.url %} // get the url is next item in the array has the same date as current item 

      // You can now use the url to navigate to the next item in the array that must have todays date 

     {% endif %} 

     {% if forloop.index == preveventindex %} 
      {{ forloop.index }} - 
      {{ event.url }} 
      {% assign preveventurl = event.url %} 

      // You can now use the url to navigate to the previous item in the array that must have todays date 

     {% endif %} 
     {% endif %} 
    {% endfor %} 

    {% endif %} 
{% endif %} 
{% endfor %} 
関連する問題