Hi, I do not have much ruby experience, so I hope anybody can give some guidance on how to create the following:
I want to create a short loop function to load a specific (short) menu. The content of the menu is different on each page, but the markup is the same. I have a page where I have a local data item called “action-menu”. Its value calls the data set I want to load from the data file action.yml. In the item I have 3 items per data set. The menu itself is put in a partial, so I can use it on any page.
I think there must a simple way to create an each function to match the current_page data with the corresponding data set and load that data set (eg. - [‘home’ => ‘home’, ‘news_an’ => ‘news_an’, etc…].each do …
So I want to
- use a frontmatter variable to load a data file set
- not having to repeat the markup, but just loop trough an array
Here is the content of the files (example):
action.yml:
home:
-
id: "#upcoming-events"
label: "Events"
icon: "event"
-
id: "#welcome"
label: "Welcome"
icon: "info"
-
id: "#content"
label: "Updates"
icon: "news"
news_an:
-
id: "#content"
label: "Article"
icon: "news"
-
id: "#go-to-group"
label: "Go to group"
icon: "users"
-
id: "#create-account"
label: "Create account"
icon: "user-add"
index.html.haml
—
action_menu: home
—
_actionmenu.haml
.action-menu
%ul.tabs
- if current_page.data.action_menu == "home"
- for item in data.action.home
%li
%a.tab{:href => "#{item.id}"}
%i.icon{:class => "icon-#{item.icon}"}
#{item.label}
- if current_page.data.action_menu == "news_an"
- for item in data.action.news_an
%li
%a.tab{:href => "#{item.id}"}
%i.icon{:class => "icon-#{item.icon}"}
#{item.label}