burguillos.info/templates/page/_desktop_menu.html.ep

25 lines
984 B
Plaintext
Raw Normal View History

% my $categories = stash 'categories';
% my $current_category_slug = stash 'current_category_slug';
<nav class="desktop"><%
my @sorted_categories = sort {
$categories->{$a}{priority} <=> $categories->{$b}{priority}
} keys %$categories;
my $target_category_slug = $current_category_slug;
my $current_category = $categories->{$current_category_slug};
if (defined $current_category) {
my $possible_parent = $current_category->{parent};
if (defined $possible_parent && defined $categories->{$possible_parent}) {
$target_category_slug = $categories->{$possible_parent}{slug};
}
}
for my $category_key (@sorted_categories) {
my $category = $categories->{$category_key};
if (defined $category->{parent}) {
next;
}
my $selected = defined($target_category_slug) && $category->{slug} eq $target_category_slug;
%><a class="<%=$selected && "selected" %>" href="<%= '/'.$category->{slug} %>"><%==$category->{menu_text}%></a><%
}
%></nav>