Add navigation link helper
Tom Rutgers
committed Aug 18, 2018
commit 1748e04b8fd5cd32a750299e8bbde356c5a7c361
Showing 3
changed files with
9 additions
and 2 deletions
config.rb
+7
-0
| @@ | @@ -58,6 +58,13 @@ helpers do |
| def background_image(image) | |
| "background-image: url('" << image_path(image) << "')" | |
| end | |
| + | |
| + | def nav_link(link_text, url, options = {}) |
| + | options[:class] ||= "" |
| + | options[:class] << " active" if url == current_page.url |
| + | link_to(link_text, url, options) |
| + | end |
| + | |
| end | |
| # Build-specific configuration | |
data/settings/navigation.yml
+1
-1
| @@ | @@ -1,5 +1,5 @@ |
| nav_items: | |
| - | - {label: 'Home', path: '#'} |
| + | - {label: 'Home', path: '/'} |
| - {label: 'Story', path: '#'} | |
| - {label: 'Products', path: '#'} | |
| - {label: 'News', path: '#'} | |
source/partials/shared/_header-primary.slim
+1
-1
| @@ | @@ -7,4 +7,4 @@ header.header-primary |
| ul | |
| - data.settings.navigation.nav_items.each do | nav_item | | |
| li | |
| - | = link_to nav_item.label, nav_item.path |
| \ No newline at end of file | |
| + | = nav_link nav_item.label, nav_item.path |
| \ No newline at end of file | |