Move more logic into Twig filter
This commit is contained in:
parent
dca8b1afb4
commit
97050c7f29
|
@ -1,13 +1,9 @@
|
|||
<div class="mt4">
|
||||
<h2>Events</h2>
|
||||
|
||||
{% set talks = [] %}
|
||||
{% for event in page.events %}
|
||||
{% set talks = talks|merge([{
|
||||
event: event|merge(site.events[event.event]),
|
||||
talk: page,
|
||||
}]) %}
|
||||
{% endfor %}
|
||||
|
||||
{% include "talks-table" with { talk_page: true } %}
|
||||
{% set data = { talks: [page], events: site.events } %}
|
||||
{% include "talks-table" with {
|
||||
talks: data|format_talks|reverse,
|
||||
talk_page: true
|
||||
} %}
|
||||
</div>
|
||||
|
|
|
@ -10,18 +10,9 @@ use: [talks]
|
|||
|
||||
<h2>Last 5 Talks</h2>
|
||||
|
||||
{% set talks = [] %}
|
||||
{% 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 %}
|
||||
|
||||
{% set data = { talks: data.talks, events: site.events } %}
|
||||
{% 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>
|
||||
|
|
|
@ -14,16 +14,7 @@ talks:
|
|||
---
|
||||
<p>Here are a list of my previous conference and user group talks:</p>
|
||||
|
||||
{% set talks = [] %}
|
||||
{% for talk in data.talks|merge(page.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 } %}
|
||||
{% set data = { talks: data.talks|merge(page.talks), events: site.events } %}
|
||||
{% include "talks-table" with { talks: data|format_talks } %}
|
||||
|
||||
<p>Upcoming talks can be found on the <a href="{{ site.url }}/talks">talks page]</a>.</p>
|
||||
|
|
|
@ -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)
|
||||
->sortByDesc('event.date')
|
||||
->all();
|
||||
|
|
Reference in a new issue