Move more logic into Twig filter

This commit is contained in:
Oliver Davies 2017-10-28 02:28:44 +01:00
parent dca8b1afb4
commit 97050c7f29
4 changed files with 24 additions and 35 deletions

View file

@ -1,13 +1,9 @@
<div class="mt4"> <div class="mt4">
<h2>Events</h2> <h2>Events</h2>
{% set talks = [] %} {% set data = { talks: [page], events: site.events } %}
{% for event in page.events %} {% include "talks-table" with {
{% set talks = talks|merge([{ talks: data|format_talks|reverse,
event: event|merge(site.events[event.event]), talk_page: true
talk: page, } %}
}]) %}
{% endfor %}
{% include "talks-table" with { talk_page: true } %}
</div> </div>

View file

@ -10,18 +10,9 @@ use: [talks]
<h2>Last 5 Talks</h2> <h2>Last 5 Talks</h2>
{% set talks = [] %} {% set data = { talks: data.talks, events: site.events } %}
{% for talk in data.talks %}
{% for event in talk.events %}
{% set talks = talks|merge([{
event: event|merge(site.events[event.event]),
talk: talk,
}]) %}
{% endfor %}
{% endfor %}
{% include "talks-table" with { {% include "talks-table" with {
talks: talks|format_talks|slice(0,5) talks: data|format_talks|slice(0,5)
} %} } %}
<p>Upcoming talks can be found in the <a href="{{ site.url }}/talks/archive">talks archive</a>.</p> <p>Upcoming talks can be found in the <a href="{{ site.url }}/talks/archive">talks archive</a>.</p>

View file

@ -14,16 +14,7 @@ talks:
--- ---
<p>Here are a list of my previous conference and user group talks:</p> <p>Here are a list of my previous conference and user group talks:</p>
{% set talks = [] %} {% set data = { talks: data.talks|merge(page.talks), events: site.events } %}
{% for talk in data.talks|merge(page.talks) %} {% include "talks-table" with { talks: data|format_talks } %}
{% for event in talk.events %}
{% set talks = talks|merge([{
event: event|merge(site.events[event.event]),
talk: talk,
}]) %}
{% endfor %}
{% endfor %}
{% include 'talks-table' with { talks: talks|format_talks } %}
<p>Upcoming talks can be found on the <a href="{{ site.url }}/talks">talks page]</a>.</p> <p>Upcoming talks can be found on the <a href="{{ site.url }}/talks">talks page]</a>.</p>

View file

@ -17,8 +17,19 @@ class FormatTalksExtension extends Twig_Extension
]; ];
} }
public function formatTalks($talks) public function formatTalks($data)
{ {
$event_data = $data['events'];
$talks = [];
foreach ($data['talks'] as $talk) {
foreach ($talk['events'] as $event) {
$event = array_merge($event, $event_data[$event['event']]);
$talks[] = compact('talk', 'event');
}
}
return collect($talks) return collect($talks)
->sortByDesc('event.date') ->sortByDesc('event.date')
->all(); ->all();