Skip to content

Instantly share code, notes, and snippets.

@pankajpatel
Created October 23, 2017 09:53
Show Gist options
  • Save pankajpatel/7730c6eaeb9a0a9b61869e72ac57f9c9 to your computer and use it in GitHub Desktop.
Save pankajpatel/7730c6eaeb9a0a9b61869e72ac57f9c9 to your computer and use it in GitHub Desktop.
Benefits of JavaScript Template Literals - Time to Hack; Read more at http://bit.ly/2ld9xYD
const topLevel = [
{ label: 'Home', url: '/home' },
{ label: 'Products', url: '/products' },
{ label: 'Services', url: '/services' },
{ label: 'About', url: '/about-us' },
{ label: 'Contact', url: '/contact-us' },
];
const social = [
{ label: '<i class="fa fa-facebook-square"></i>', url: 'https://facebook.com/time2hack' },
{ label: '<i class="fa fa-twitter-square"></i>', url: 'https://twitter.com/time2hack' },
{ label: '<i class="fa fa-google-plus-square"></i>', url: 'https://plus.google.com/+Time2hack' },
]
const menu = (menuData) => `
<ul class="nav">
${menuData.map(item => `
<li class="nav-item">
<a class="nav-link" href="${item.url}">${item.label}</a>
</li>
`)}
</ul>
`;
document.querySelector('body > header').innerHTML += menu(topLevel);
document.querySelector('body > footer').innerHTML += menu(social);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment